我正在使用Laravel中的一个项目并使用DB facade来运行sql的原始查询.在我的情况下,我使用DB :: select,问题是分页方法不能使用此DB原始查询并显示此错误
Call to a member function paginate() on array
Run Code Online (Sandbox Code Playgroud)
我只想要如何用DB原始查询实现laravel分页这里是我的代码:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Notice;
use Illuminate\Support\Facades\DB;
use Illuminate\Pagination\Paginator;
use Illuminate\Pagination\LengthAwarePaginator;
class NoticeController extends Controller
{
public function index(){
$notices = DB::select('select
notices.id,notices.title,notices.body,notices.created_at,notices.updated_at,
users.name,departments.department_name
FROM notices
INNER JOIN users ON notices.user_id = users.id
INNER JOIN departments on users.dpt_id = departments.id
ORDER BY users.id DESC')->paginate(20);
$result = new Paginator($notices,2,1,[]);
return view('welcome')->with('allNotices', $notices);
}
}
Run Code Online (Sandbox Code Playgroud) 我只想知道身份验证路由在哪里定义。就我而言,我已登录,但出于测试目的,尝试再次使用登录页面
localhost/login
Run Code Online (Sandbox Code Playgroud)
这应该将我带到我的仪表板或个人资料,但它重定向到“/home”并且无法找到此视图。如何配置此路由以及在 Laravel 中的何处配置此路由。