在Laravel

时间:2018-04-22 19:51:31

标签: database laravel foreign-keys

尝试禁用外键约束。这就是create users表现在的样子。尝试使用disableForeignKeyConstraints方法,但迁移时没有运气。我也尝试在创建模式之后使用enableForeignKeyConstraints方法,但这也没有帮助。对此的任何帮助将不胜感激。

Blog Post Controller:

public function index(){
    $blog_posts = BlogPost::all();
    return view('whatsnew.index', compact("blog_posts"));
}

public function show($blog_post){
    $blog_post = BlogPost::find($blog_post);
    return view('whatsnew.show', compact("blog_post"));
}

public function create(){
    return view('whatsnew.create');
}

public function store(BlogPostRequest $request){
    $formData = $request->all();

    BlogPost::create($formData);

    return redirect('whatsnew');
}

public function edit($blog_post){
    $blog_post = BlogPost::findOrFail($blog_post);

    return view('whatsnew.edit', compact("blog_post"));
}

public function update(BlogPostRequest $request, $blog_post){
    $formData = $request->all();
    $blog_post = BlogPost::findOrFail($blog_post);
    $blog_post->update($formData);

    return redirect('whatsnew');
}

public function __construct(){
    $this->middleware('auth', ['only' =>['create', 'edit', 'destroy']]);
}

public function destroy(BlogPost $blog_post){
    $blog_post->delete();
    return redirect('whatsnew');
}

0 个答案:

没有答案