我有一个主站点和一个管理控制面板。
我希望每个版本都有不同的 404 页。
我该怎么做?我目前在我的app/Exceptions/Handles.php文件中有以下代码:
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $exception
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $exception)
{
if($exception instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException)
{
$view = $request->is('admin/*') ? 'acp.errors.404' : 'errors.404' ;
return response()->view($view, [], 404);
}
return parent::render($request, $exception);
}
Run Code Online (Sandbox Code Playgroud)
但是我使用该包spatie/laravel-permission并收到以下错误;
Trying to get property 'role' of non-object (View: F:\Development\RPR\site\resources\views\layouts\acp.blade.php) (View: F:\Development\RPR\site\resources\views\layouts\acp.blade.php)
Run Code Online (Sandbox Code Playgroud)
我使用 in acp.blade.php auth()->user()->role, 来获取用户角色,它可以正常工作,没有任何例外。我应该如何解决这个问题?
我在 XAMPP 堆栈上使用 Laravel 5.8。
考虑这两个迁移来创建两个表:
post_categories 表。
Schema::create('post_categories', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->string('slug');
$table->string('status');
$table->timestamps();
});
Run Code Online (Sandbox Code Playgroud)
帖子表。
Schema::create('posts', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->string('slug');
$table->mediumText('description');
$table->integer('views');
$table->integer('post_category_id')->unsigned();
$table->integer('user_id')->unsigned();
$table->timestamps();
$table->foreign('post_category_id')->references('id')->on('post_categories');
});
Run Code Online (Sandbox Code Playgroud)
当我运行时php artisan migrate,我收到以下错误:
一般错误:1005 无法创建表
testdb。#sql-38d8_102(错误号:150“外键约束的格式不正确”)。
我试过同时运行:
php artisan migratephp artisan migrate:fresh我还尝试将post_category_id字段更改为常规整数,而不是无符号:没有区别。
还重新启动了 MySQL 服务器和 Apache 服务,没有任何区别。
在post_categories迁移运行前的posts迁移。该posts表被创建,但外键不。
为什么会抛出这个错误,我该如何解决?