Form action not working in laravel

对着背影说爱祢 提交于 2019-12-12 03:51:28

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!