I am using the Forms provided by Laravel Collective and it is correctly installed.
What I'm trying to do is to validate the Form in PictureController.php
Just like this:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Picture;
use DB;
class PictureController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$pictures = Picture::all();
return view('welcome')->with('pictures', $pictures);
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('pictures.publicize');
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$this->validate($request, [
'hashtag' => 'required',
]);
return 123;
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
And this is the code snippet of publicize.blade.php
which contains this form.
{!! Form::open(array(
'action' => 'PictureController@store',
'method' => 'POST',
'files' => true
))
!!}
<div class="form-group">
{{ Form::label('hashtag', 'HashTag') }}
{{ Form::text('hashtag', '', ['placeholder' => 'Eg. #Happiness', 'class' => 'form-control', 'name' => 'hashtag' /*'required'*/]) }}
</div>
{{ Form::submit('Publicize', ['class' => 'btn btn-primary']) }}
{!! Form::close() !!}
And in the routes/web.php
, this is the code written...
Route::resource('/', 'PictureController');
I have also submitted whole code on GitHub. Just look at this commit to take a look at all the files.
The problem is..
When I look into the Source Code in browser, I see that action
attribute in the form equals the home url, i.e /public/
. It looks like the form is not connected to the controller and method I specified in publicize.blade.php
. How can I make that form work properly with validations?
Thanks for help in advance.