Handle form submission Laravel 5

I just start learning Laravel 5, and I want to know what the proper way to handle submitted forms. I found many tutorials where we create two separate actions, where first render form, and the second actually handle form. I am came from Symfony2, where we create a single action for both, render and handle submitted form, so I want to know I need to create two separate actions because thats Laravel-way, or I can place all logic into single action, I do this like the folowing, but I dont like code what I get:

public function create(Request $request)
{
    if (Input::get('title') !== null) {
        $v = Validator::make($request->all(), [
            'title'   => 'required|unique:posts',
            'content' => 'required',
        ]);
        if ($v->fails()) {
            return redirect()->back()->withErrors($v->errors());
        }
        $post = new Post(Input::all());
        if ($post->save()) {
            return redirect('posts');
        }
    }

    return view('add_post');
}

So can somebody give me advice how I need do this properly? Thanks!


Source: forms

Leave a Reply