How to send data using redirect with Laravel
In store()
return Redirect::route('clients.show, $id')->with( ['data' => $data] );
and in show()
read it with
Session::get('data');
Laravel- redirect with variable and display it in the view file
You should try this:
public function store(Request $request)
{if ($request->input('asc')){
$image = PropertyUser::where('user_id', '=', Auth::user()->id)->get();
foreach($image as $property)
{
$id = $property->property_id;
}
$image_ = Image::where('property_id', $id)->sortBy('description')->get();
return view('yourfolder.yourviewfile',compact('image_'));
Updated Answer
use Redirect;
public function store(Request $request)
{if ($request->input('asc')){
$image = PropertyUser::where('user_id', '=', Auth::user()->id)->get();
foreach($image as $property)
{
$id = $property->property_id;
}
$image_ = Image::where('property_id', $id)->sortBy('description')->get();
Redirect::to('settings/photos?image_='. $image_);
How to send data to the view using redirect with Laravel without using Session?
There's no other way, you really need to use Session::get
. However, we can do a workaround it, but it's messy.
// some controller function
return redirect('home')->with(['data' => $value]);
Now in your home
controller function, do this:
SomeController@home
...
$data = [];
// if you need to pass other data to view, put it in data[]
// e.g., $data['username'] = Auth::user()->username;
if (Session::has('data')) {
$data['data'] = Session::get('data');
}
return view('myView', compact($data));
There, in your view you can just check if data
is set.
<!-- myView.blade.php -->
<span>{{ isset($data) ? $data : '' }}</span>
For me, it's merely the same as accessing the Session
from the view, because if you did, this is what your view will look like.
<!-- myView.blade.php -->
<span>{{ Session::has('data') ? Session::get('data') : '' }}</span>
You can also use session()
global helper instead of the Session
facade.
laravel 8 passing data to redirect url
i found the solution:
web.php
Route::get('invoicelink/{invoice}', [OrderController::class, 'invoicelink'])->name('invoicelink');
controller:
public function invoicelink($invoice)
{
//dd($invoice);
return $invoice;
}
then use redirect:
return redirect()->route('invoicelink', [$invoice]);
Laravel route redirecting with data
Following up on the comment
You can create a Route in routes/web.php file that catches non-digit ids and redirect this to 'view-user' with id=1
It would look something like this
Route::get('/group/{uuid}/user/{id}', function ($uuid, $id) {
return redirect('view-user', ['uuid' => $uuid, 'id' => 1]);
})->where('id', '[^0-9]+');
// and then below have your normal route
Route::get('/group/{uuid}/user/{id}', 'Controller@preview')->name('view-user')->where('id', '[0-9]+');
Update
Following you comment that you do not want to use closures.
Change the "bad input route" to
Route::get('/group/{uuid}/user/{id}', 'Controller@redirectBadInput')->where('id', '[^0-9]+');
and then add the method in class Controller
:
public function redirectBadInput ($uuid, $id) {
return redirect('view-user', ['uuid' => $uuid, 'id' => 1]);
}
You can see more in this SO thread about redirects and caching.
Redirect with compact value in laravel
Try this
return redirect()->route('Merchant view')->with( ['merchant' => $merchant] );
In blade file :
<?php $merchants = Session::get('merchant'); ?>
@foreach ($merchants as $merchant)
//your code
@endforeach
Hope it helps you !
Redirect from controller to named route with data in laravel
public function match(Request $request)
{
// Operations
$list = //Data Collection;
return redirect()->route('form.matches')->with('list',$list);
}
In view
@if(Session::has('list'))
<div>
{!!Session::get('list')!!}
</div>
@endif
Related Topics
How to Count Columns With the Same Value in a Specific Row in MySQL
How to Get Only Date from Datetime in Codeigniter
How to Prevent Mails Sent Through PHP Mail() from Going to Spam
Increase a Value Like = +1 in MySQL and PHP
Undefined Index: User_Id. Where, User_Id Is Session Variable
Remove Comma on Last Item of Foreach
How to Make a Checkbox Checked and Disabled
How to Do Multilevel Menu the Correct Way With MySQL PHP
How to Parse a Json File With PHP
How to Get Woocommerce Order Details
How to Fetch Record of Many Ids on Single Query
Php Fatal Error: Uncaught Pdoexception: Could Not Find Driver
Laravel 6: Call to Undefined Method App\\User::Createtoken()
Getting Data from a Textarea into a Database