Retrieving Get and Post Data Inside Laravel Controller

How to get All input of POST in Laravel

Try this :

use Illuminate\Support\Facades\Request;
public function add_question(Request $request)
{
return $request->all();
}

Laravel get POSTed data using request

In Laravel, you can fetch the request input data by using $request->all(). This will then return the input data as an array. You can find more in the docs here.

Laravel - Passing POST data to view from controller

You can get the request data in an array using:

$data = $request->all();
return view('planner_newsummary', $data);

(reference)

You can also exclude or only include certain data by using:

$input = $request->only(['username', 'password']);

$input = $request->only('username', 'password');

$input = $request->except(['credit_card']);

$input = $request->except('credit_card');

(reference)

You can then pass this data into the view however you wish, once inside the view you can iterate through the list using blade using a for loop (reference).

This will also will give you enough information regarding associative array loop in Blade. Click.

If you need more clarification let me know,

Thanks,

Laravel: how to get data with post

with works with key value pair

Route::post('/trans',  function(){
$j = Input::get('r');
return view('movs.create')->with('j',$j);
// or return view('movs.create', compact('j')); // it will extract in
//blade as $j
// or return view('movs.create', ['j' => $j]);
});

// you can fetch that data in blade as {{$j}}

<input type="number" class="form-control" name="id_coop" value="{{$j ?? ''}}" readonly/> 

Example of with,

return view('greeting')->with('name', 'Victoria'); // name as key and Victorial as value.

{{$j ?? ''}} if data is not set then '' value.

How do i fetch data inside a controller using laravel

get returns a collection. You should use first to get the first result from your query:

DonorDetail::where('donation_id', $paytmResponse['ORDERID'])->first();

If no results were found, null will be returned, so you should also pay attention to that.

You only provided us with a small portion of your code, but it seems like you're doing a lot of things in a non-Laravel way. It's only natural because, as you mentioned, you're just starting with Laravel. My recommendation to you is to check out Laracast's free "Laravel From Scratch" course:
https://laracasts.com/series/laravel-6-from-scratch

It's by far the best resource for developers taking their first steps in Laravel (and it also has good resources for experienced developers).

Good luck!

Passing data from controller to view in Laravel

Can you give this a try,

return View::make("user/regprofile", compact('students')); OR
return View::make("user/regprofile")->with(array('students'=>$students));

While, you can set multiple variables something like this,

$instructors="";
$instituitions="";

$compactData=array('students', 'instructors', 'instituitions');
$data=array('students'=>$students, 'instructors'=>$instructors, 'instituitions'=>$instituitions);

return View::make("user/regprofile", compact($compactData));
return View::make("user/regprofile")->with($data);


Related Topics



Leave a reply



Submit