Reputation: 188
I'm sending parameters from one to another without passing them through the route pass them another way for security, but the problem with the last function is that it loses the parameter and even dd()
doesn't work, it returns the view only with an undefined variable $data
.
Controller
// Pass id to test.auth
public function show_auth($id)
{
return view('test.auth', compact('id'));
}
// Here it gets id and dd($data) works
public function post_auth(Request $request)
{
$id = $request->id;
$data = DB::table('kuponai')->where('id', $id)->get();
//dd($data);
return view('test.view', compact('data'));
}
// Function from before dump doesn't work and returns view
public function view($data)
{
dump($data);
return view('test.view');
}
Changed for this doesn't work neither...
public function check(Request $request)
{
$id = $request->id;
//
return view('test.auth',compact('id'));
}
public function show_auth($id)
{
return view('test.auth',compact('id'));
}
public function post_auth(Request $request)
{
$id = $request->id;
$pin = $request->pin;
$mail = $request->elpastas;
$data = DB::table('kuponai')
->where('id', $id)
->get();
//dd($data);
return route('view.show',compact('data'));
}
public function view($data)
{
$d = $this->post_auth($data);
//dd($data);
return view('test.view');
}
Upvotes: 0
Views: 120
Reputation: 308
This is likely because the data variable you passed is sent directly to the test.view
view. So never pass the view function ($ data) you do dump($data)
.
($ data is sent not via a route, but directly into the view) !!
I seem to know the solution, but please show me your snippet of routes.php
Routes:
Route::group(['domain' => 'coupons.domain.com'], function()
{
Route::get('/', 'App\Http\Controllers\IsoreController@index')->name('view.klientas');
Route::post('/check', 'App\Http\Controllers\IsoreController@check')->name('check')->middleware('checkid');
// view authenticated coupon
Route::get('/view', 'App\Http\Controllers\IsoreController@view')->name('view.show')->middleware('checkpin');
// show coupon authenticate form
Route::get('/auth','App\Http\Controllers\IsoreController@show_auth')->name('show.auth')->middleware('checkid');
// handle user input, authenticate coupon
Route::post('/authenticate','App\Http\Controllers\IsoreController@post_auth')->name('post.auth')->middleware('checkpin');
});
Try to replace return view('test.auth', compact('data'));
With:
return redirect('/view')->with(compact('data'));
My middlewares:
checkid:
class KuponoId {
public function handle($request, Closure $next)
{
$exists =Kuponas::where('id', $request->id)->exists();
if (!$exists) {
return \Redirect::to(url('/'))->with('pin','Duomenys neteisingi, patikrinkite ');
}
return $next($request);
}
}
checkpin:
class CheckPin {
public function handle($request, Closure $next)
{
$exists = Kuponas::where('patvirtinimo_kodas', $request->pin)->where('elpastas', $request->elpastas)->where('id', $request->id)->exists();
//dd($exists);
if (!$exists) {
//return \Redirect::to(url('/'))->with('pin','Duomenys neteisingi, patikrinkite ');
return \Redirect::to(url('/'))->with('pin','Duomenys neteisingi! ');
}
return $next($request);
}
}
i just need to show info view for just that one time when user authentificates correctly
Oke, hhow about this?
return redirect()->action( 'TheController@view', ['id' => 1] );
Upvotes: 2