传递给App \ Providers \ AuthServiceProvider :: App \ Providers \ {closure}()的参数2必须是App \ Post的实例,给定字符串,

时间:2019-02-21 10:26:02

标签: laravel-5.7

当我尝试在laravel 5.7应用程序上编辑博客帖子时,出现上述错误。有关如何解决此问题的任何想法?

我的帖子控制器;

public function edit($id)
{

    $post = Post::find($id);
    return view('posts.edit')->withPost($post);
}

/**
 * Update the specified resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function update(Request $request, $id)
{
    // Form validation
    $this->validate($request, array(
        'title' =>'required|max:190',
        'category' =>'required|max:190',
        'body' =>'required'
    ));

    //save in db
    $post = Post::find($id);
    $post->title=$request->input('title');
    $post->category=$request->input('category');
    $post->body=Purifier::clean($request->input('body'));
    $post->save();
    Session::flash('success','Blog successfuly updated!');

    return redirect()->route('posts.show',$post->id);
}

我的AuthServiceProvider;

public function registerPostPolicies()
{
  Gate::define('create-post', function($user){
    $user->hasAccess(['create-post']);
  });

  Gate::define('update-post', function($user, Post $post){
    $user->hasAccess(['update-post']) or $user ->id ==$post -> user_id;
  });

  Gate::define('delete-post', function($user, Post $post){
    $user->hasAccess(['delete-post']) or $user ->id ==$post -> user_id;
  });
}

我花了几个小时来解决问题,但似乎没有任何进展。

任何帮助将不胜感激

0 个答案:

没有答案