Laravel 迁移 Darabase 时出错:BadMethodCallException 方法 \Blueprint::url 不存在
Laravel Error Migrating Darabase: BadMethodCallException Method \Blueprint::url does not exist
我是 Laravel 的新手,所以如果这很明显,那么我很抱歉,但我不知道这是什么意思。我只是想添加一个允许用户添加新 post 的功能。我遇到了问题所以我尝试了回滚,这很好但是当我再次尝试迁移时我得到了这个:
这里是创建posttable:
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatePostsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('posts', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('user_id');
$table->string('title');
$table->text('thought');
$table->url('url')->nullable();
$table->string('image')->nullable();
$table->timestamps();
$table->index('user_id');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('posts');
}
}
这是我的 Post.php :
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
protected $gaurded = [];
public function user(){
return $this->belongsTo(User::class);
}
}
PostsController.php :
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class PostsController extends Controller
{
public function create(){
return view('posts.create');
}
public function store(){
$data = request()->validate([
'title',
'thought',
'image',
'url'
]);
auth()->user()->posts()->create($data);
dd(request()->all());
}
}
而且我不知道该怎么做。因为我不知道发生了什么,所以我真的不知道您可能还需要什么其他信息,但如果还有其他任何有助于解决此问题的信息,请告诉我。任何建议都会很棒。
我认为是因为你在迁移文件中使用了"url"数据类型而在"Blueprint"[=17=中没有这样的方法] 的 laravel.So 这就是发生错误的原因。
我是 Laravel 的新手,所以如果这很明显,那么我很抱歉,但我不知道这是什么意思。我只是想添加一个允许用户添加新 post 的功能。我遇到了问题所以我尝试了回滚,这很好但是当我再次尝试迁移时我得到了这个:
这里是创建posttable:
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatePostsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('posts', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('user_id');
$table->string('title');
$table->text('thought');
$table->url('url')->nullable();
$table->string('image')->nullable();
$table->timestamps();
$table->index('user_id');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('posts');
}
}
这是我的 Post.php :
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
protected $gaurded = [];
public function user(){
return $this->belongsTo(User::class);
}
}
PostsController.php :
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class PostsController extends Controller
{
public function create(){
return view('posts.create');
}
public function store(){
$data = request()->validate([
'title',
'thought',
'image',
'url'
]);
auth()->user()->posts()->create($data);
dd(request()->all());
}
}
而且我不知道该怎么做。因为我不知道发生了什么,所以我真的不知道您可能还需要什么其他信息,但如果还有其他任何有助于解决此问题的信息,请告诉我。任何建议都会很棒。
我认为是因为你在迁移文件中使用了"url"数据类型而在"Blueprint"[=17=中没有这样的方法] 的 laravel.So 这就是发生错误的原因。