How to pass the custom variables from ResetPasswordController to reset blade - laravel

How to pass the custom variables from ResetPasswordController to reset blade template.
ResetPasswordController.php
public function showResetForm(Request $request, $token = null)
{
$data = array(
'title'=>'Reset password',
'description'=> 'Reset password to abc.com',
'seo_keywords'=> 'Reset password to abc.com',
);
return view('auth/password/reset',$data);
}

By returning a view(), the second argument can be used to pass variables to the blade template (just like you have done)
public function showResetForm(Request $request, $token = null)
{
return view('auth/password/reset',[
'title' =>'Reset password',
'description' => 'Reset password to abc.com',
'seo_keywords' => 'Reset password to abc.com',
]);
}
These would then be accessable as {{ $title }}, {{ $description}}, {{ $seo_keywords}}.
If you are unable to retrieve these, it may be because you are editting the wrong blade template. The default template is located at auth.passwords.reset (resources/views/auth/passwords/reset.blade.php).
I'd suggest just adding a {{ dd('here) }} at the top of that template to make sure it is in fact the template being used by your application!

Related

Laravel Cannot Decrypt Encrypted ID On Controller

I cannot decrypt the encrypted value on a controller after clicking on the submit button on my blade file below.
Controller :
public function edit($id)
{
$encrypted_id = encrypt($id);
return view('my.blade.edit', compact('encrypted_id'));
}
public function update(Request $request, $id)
{
$decrypted_id = decrypt($id);
dd($decrypted_id);
}
Blade: (my.blade.edit)
{{ Form::open(['route' => ['route.update', $encrypted_id ], 'method' => 'PATCH']) }}
{{ Form::button('Update', ['type' => 'submit', 'name' => 'update']) }}
{{ Form::close() }}
I am expecting an integer value on my dd(); but I still getting an encrypted string.
Well, as I've already written in the comments, first and simple is to check expected output and exact output.
So far we discovered, that value was sent to view isn't equal to value received in update() method.
id was encrypted twice, but we don't see two encrypt() calls in the code from the question. Probably some other code layer was making that.

How to pass array in Mail Function in Laravel 5.7

Below is my mail function:
How to can I pass an array to mail function?
public function mail(Request $request , $id) {
$data=[
'owner'=>MyRoom::where('id',$id)->get(),
'data2'=>$request->all(),
];
Mail::send('emails.mail' , $data, function($message) use ($data){
$message->to($owner->created_by->email , $owner->created_by->name)
->subject('Room showing Request From OpenRoomList');
$message->from('regmibipin13#gmail.com','OpenRoomList');
});
echo "Email Send check your inbox";
}
Firstly instead of doing get which will give you a collection, do :
'owner' => MyRoom::find($id);
In your resources/emails/mail.blade.php blade file you can directly use $owner and $data2 variables using blde syntax like : {{ $owner->somecolumn }} and {{ $data2['somefield'] }}

Laravel 5.5 - Missing required parameters for [Route:]

What I'm trying to achieve is very simple, but I'm just making this a lot harder than it needs to be. So am seeking help for what is apparently, my lack of Laravel experience.
All I want to do is have a form that can update database entries via a text input. This has to be dynamic as it's being used for a few databases and I don't want to have multiple files for them.
Sorry in advance for the probable messy/crap code...
Here's the routes I have:
Route::get('/server/{server}/players/{playerID}/greeting', 'PlayerProfileController#greeting');
Route::post('/server/{server}/players/{playerID}/greeting', 'PlayerProfileController#updateGreeting')->name('greeting.update');
The PlayerProfileController
// Display greeting message
public function greeting($server, $playerID) {
$greetInfo = DB::connection($server)
->table('clients')
->where('id', $playerID)
->first();
return view('servers.greeting')
->with('greetInfo', $greetInfo);
}
// Update greeting message
public function updateGreeting(Request $request, $server, $playerID) {
$gUpdate = DB::connection($server)
->table('clients')
->where('id', $playerID)
->update(['greeting' => $request->input('greet')]);
return back()->with('success', 'Greeting updated successfully!');
}
And finally the form
{{ Form::open(['action' => ['PlayerProfileController#updateGreeting', $greetInfo->greeting], 'method' => 'POST']) }}
{{ Form::bsText('greet', '', ['placeholder' => 'Update greeting or leave blank to remove current message']) }}
{{ Form::hidden('_method', 'PUT') }}
<br>
{{ Form::bsSubmit('Update',['class' => 'btn btn-outline-secondary']) }}
{!! Form::close() !!}
Any and all help is appreciated. Thank you in advace.
The ErrorException you're seeing is caused by the missing argument for the route you're trying to call. Your route is expecting server and playerId, wheres you're only sending it $greetInfo->greeting.
As you're using named route, my suggestion would be to use route() helper like so:
Route::get('/server/{server}/players/{playerID}/greeting', 'PlayerProfileController#greeting');
Route::post('/server/{server}/players/{playerID}/greeting', 'PlayerProfileController#updateGreeting')
->name('greeting.update');
class PlayerProfileController extends Controller {
public function greeting($server, $playerID) {
$greetInfo = DB::connection($server)
->table('clients')
->where('id', $playerID)
->first();
return view('servers.greeting')
->with('greetInfo', $greetInfo);
}
// Update greeting message
public function updateGreeting(Request $request, $server, $playerID) {
$gUpdate = DB::connection($server)
->table('clients')
->where('id', $playerID)
->update(['greeting' => $request->input('greet')]);
return back()->with('success', 'Greeting updated successfully!');
}
}
{{ Form::open(['action' => route('greeting.update', [$server, $playerId]), 'method' => 'post']) }}
{{ Form::bsText('greet', '', ['placeholder' => 'Update greeting or leave blank to remove current message']) }}
{{ Form::bsSubmit('Update',['class' => 'btn btn-outline-secondary']) }}
{!! Form::close() !!}
Please replace $server and $playerId variables with the ones representing the arguments you want to send with the request.
You can see I've also removed {{ Form::hidden('_method', 'PUT') }}, as this was trying to overwrite the post method on the Form::open method.

Laravel undefine variable in view

I'm new to laravel. Using version 5.4 and tried to search but don't see what I'm doing wrong. I keep getting an "Undefined variable: post" in my view. I'm also doing form model binding. Model binding works properly when manually entering URL. Just can't click on link to bring up edit view.
My routes:
Route::get('test/{id}/edit','TestController#edit');
My controller:
public function edit($id)
{
$post = Post::find($id);
if(!$post)
abort(404);
return view('test/edit')->with('test', $post);
}
My form:
{{ Form::model($post, array('route' => array('test.update', $post->id), 'files' => true, 'method' => 'PUT')) }}
You're assigning the post value to 'test', so should be accessible with $test rather than $post.
You probably want to do either of these two things instead:
return view('test/edit')->with('post', $post);
or
return view('test/edit', ['post' => $post]);
https://laravel.com/docs/5.4/views
Your controller is sending a variable named "test", but your error says that your blade file doesn't have the $post variable passed into it. This can be fixed by changing "test" to "post" in your controller.

Missing required parameters for in a Update Form Laravel 5.2

I've been working on a webapp recently in laravel and i wanted to have a eddit function within tthe application. but im getting this error Missing required parameters for [Route: producten.update] [URI: producten/{producten}], and i dont know what i've done wrong.
This is the Routes im using:
Route::resource('producten', 'ProductenController', ['only' => ['index', 'store', 'update', 'delete', 'edit', 'destroy', 'create']]);
This is the controller function im using for showing the edit page and updating.
The Edit function
public function edit(Request $request, Product $product)
{
// $product = Product::FindorFail($id);
// Product is a table with all products, with sellprice and buy price
// fabriek = table that has a foreign key attached to the product table
return view('producten.edit', [
'model' => $product,
'fabrieks' => Fabriek::lists('Id')
]);
}
The Update Function:
public function update(Request $request, Product $product)
{
$product->update($request->all());
return redirect(Route('producten.index'));
}
and this is the view i use for it.
{{Form::model($model, ['method' => 'PATCH', 'action' => 'ProductenController#update', $model ]) }}
{{ Form::label('naam:')}}
{{ Form::text('naam') }} <br>
{{ Form::label('inkoopPrijs:')}}
{{ Form::text('inkoopPrijs') }} <br>
{{ Form::label('verkoopPrijs:') }}
{{ Form::text('verkoopPrijs') }} <br>
{{Form::label('Fabrieken', 'Fabrieken Id:') }}
{{ Form::select('Fabrieken_Id', $fabrieks)}} <br>
{{ Form::submit('edit')}}
{{ Form::close() }}
if there is anything else that i need to add to the question just let me know and i'll add it
Missing thing is the id you are not getting id there in your edit function
your edit function should as i am assuming that you are just showing the form from this method where user can edit
public function edit($id)
{
$product = Product::FindorFail($id);
//Product is a table with all products, with sellprice and buy price
//fabriek = table that has a foreign key attached to the product table
return view('producten.edit', [
'model' => $product,
'fabrieks' => Fabriek::lists('Id')
]);
}
your update method should seem like this
public function update(Request $request, $id)
{
$product->update($request->all());
return redirect(Route('producten.index'));
}
your routes should like this no need for only
Route::resource('/producten', 'productionController');
edit route will be as
<a href="{{ route('production.edit', $model->id) }}">
Try this hope it will help

Resources