Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i post data from view to controller in laravel 5.0?

Tags:

php

laravel

I'm new in laravel, i'm trying to pass data from view to controller but getting some errors. I have searched but didn't got how can i solve this issue. Please view my code and advice me where i'm wrong?

demoview.blade.php Code

echo Form::open(array( 'method' => 'post','action' => 'DemoController@savess'));
echo Form::label('name', 'Name');
echo Form::text('name');
echo Form::label('email', 'E-Mail Address');
echo Form::text('email');
echo  Form::close();

DemoController.php Code

    namespace App\Http\Controllers;

    use Illuminate\Http\Request;

class DemoController extends Controller {

    /*
    |--------------------------------------------------------------------------
    | Welcome Controller
    |--------------------------------------------------------------------------
    |
    | This controller renders the "marketing page" for the application and
    | is configured to only allow guests. Like most of the other sample
    | controllers, you are free to modify or remove it as you desire.
    |
    */

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest');
    }

    /**
     * Show the application welcome screen to the user.
     *
     * @return Response
     */
    public function demofunction()
    {
        $users = \DB::table('user')->get();
        foreach ($users as $user)
        {
            echo  $user->name;
            echo  $user->email;
        }

        return view('demoview');
    }

    public function savess(){
    }
}

Routes.php Code

Route::get('demo', 'DemoController@demofunction');

Error :

ErrorException in compiled.php line 8658:
Action App\Http\Controllers\DemoController@savess not defined. (View: E:\xampp\htdocs\ayaz\resources\views\demoview.blade.php)




InvalidArgumentException in compiled.php line 8658:
Action App\Http\Controllers\DemoController@savess not defined.
like image 523
Ayaz Shah Avatar asked Oct 12 '15 06:10

Ayaz Shah


People also ask

How pass data from modal to controller in Laravel?

add a different rout: Route::POST('/dashboard/update/{id}', 'DashboardController@update'); Controller: public function update(Request $request, $id) { $the_id = $id; //this is the id. dd($id); //to check your id value. }

How do you call a controller inside a view in Laravel 5?

$varbl = App::make("ControllerName")->FunctionName($params);

How pass data from one view to another in Laravel?

There are various ways of passing data to views:By using the name array. By using with() function. By using compact() function.


1 Answers

Add to routes.php this line:

Route::post("savess", "DemoController@savess");
like image 77
Peter Kota Avatar answered Sep 28 '22 03:09

Peter Kota