Ado*_*ene 8 php laravel laravel-5
我有一个控制器
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 redirect('settings/photos');
Run Code Online (Sandbox Code Playgroud)
我如何使用$image_变量重定向并将其显示在我的视图文件中
@foreach ($image_ as $images)
<div class="image-warp"><img src="{{$images->filename}}"
style="width:100px;height:100px;"><br/><span style="color: #1b1e21">{{$images->description}}</span>
</div>
@endforeach
Run Code Online (Sandbox Code Playgroud)
小智 7
您还可以使用以下语法发送变量
return view('viewfile')->with('card',$card)->with('another',$another);
Run Code Online (Sandbox Code Playgroud)
您可以使用重定向方法发送数据。这些数据将存储在会话类中。
return redirect('url')->with('message',$message);
Run Code Online (Sandbox Code Playgroud)
像下面这样
Session::get('variableName');
Session::get('message');
Run Code Online (Sandbox Code Playgroud)
你应该尝试这个:
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_'));
Run Code Online (Sandbox Code Playgroud)
更新答案
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_);
Run Code Online (Sandbox Code Playgroud)