jeudi 17 septembre 2020

Laravel - Post Policy Didn't Redirect Back to Post Index

I am studying web with laravel framework. I have a problem for creating authorization policies.

the problem is i cannot redirect back to post.index using Create, and didn't save in phpMyAdmin. Edit, Update, and Delete function are worked.

This is my code:

PostController.php

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

    public function store(){
        $this->authorize('create', Post::class);
        $inputs = request()->validate([
            'title'=>'required|min:8|max:255',
            'post_image'=>'file', //mime: jpeg, png
            'body'=>'required'
        ]);
        if(request('post_image')){
            $inputs['post_image'] = request('post_image')->store('images');
        }
        auth()->user()->posts()->create($inputs);
        session()->flash('post-create-message', 'Post was Created ' . $inputs['title']);
        // return back();
        return redirect()->route('post.index');
    }

    

    

and this PostPolicy.php:

public function create(User $user)
    {            
        return $user->is($user);
    }



Aucun commentaire:

Enregistrer un commentaire