lundi 17 février 2020

Object of class Illuminate\Database\Query\Builder could not be converted to string in Laravel

when i'm trying to delete a post i got this error..

this problem appeared after i implementing Arabic slugs

any idea to solve this problem ?

controller

public function update(Request $request, $id)
{
    $post = Post::find($id);

    if ($request->isMethod('get'))
        return view('content.admin.post.index', ['url' => Post::find($id)]);
    else {
         if ($request->input('slug') == $post->slug) {
            $rules = [
            'title' => 'required|max:255',
            'body'  => 'required'
        ];
    } else {
        $rules = [
            'title'         => 'required|max:255',
            'slug'          => 'required|min:3|max:255|unique:posts,slug,{$post->slug},slug',
            'body'          => 'required',
            ];}
        $this->validate($request, $rules);
        $post = Post::find($id);

        $post->title = $request->title;
        $post->slug = $this->slug($request->slug);
        $post->body = $request->body;
        $post->save();

        return redirect('/admin/posts');
    }
}
public function destroy($id)
{
    $post = Post::findOrFail($id);
    $post->delete();
    return redirect('/admin/posts')->with('success', 'Post is successfully deleted');
}


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/39NFB9T
via IFTTT

Aucun commentaire:

Enregistrer un commentaire