问题
I want to insert data in database. i found a problem. I have 2 blade.php page. 1. dashboard.blade.php and another is class.blade.php. When i use in my form action dashboard.blade.php its working. but when i used in action class.blade.php its not working. i can't found this problem. Here is my form action :
<form class="form-horizontal" role="form" method="POST" action="{{ url('/dashboard') }}">
{!! csrf_field() !!}
when i changed it
<form class="form-horizontal" role="form" method="POST" action="{{ url('/class') }}">
{!! csrf_field() !!}
then its not working. Here is my controller
public function showclass(Request $request)
{
$randomnumber = rand(50001,1000000);
$classrooms = new Classrooms();
$classrooms->class_name = $request['class_name'];
$classrooms->subject_name = $request['subject_name'];
$classrooms->section = $request['section'];
$classrooms->class_code = $randomnumber;
$classrooms -> user_id = Auth::user()->id;
$classrooms -> save();
Flash::success('Your status has been posted');
//return redirect(route('dashboard'));
return view('dashboard', array('classroom' => Auth::user()) );
}
回答1:
There is an error in your Route. You have used showdata method instead of showclass. Just change it like below:
Route::post('/class', [
'uses' => 'classroom@showclass',
'as' => 'classrooms']);
Note: Make sure to specify specific method while defining the routes.
来源:https://stackoverflow.com/questions/39067623/form-action-not-working-in-laravel