Named routes with two $param(s) - Laravel 4 - php

I'm trying to use two params with a named route through a controller, but receive an error when loading the view
Route
Route::get('agendarVehiculo/{idvehiculo}/{idcita}', array('as' => 'agendarVehiculo', 'uses' => 'AgendamientosController#addAgendaCitaVehiculo'));
View
<td>
<i class="fa fa-calendar"> Agendar</i>
</td>
Error
syntax error, unexpected '['
Any idea would be greatly appreciated Thanks!

Is your PHP 5.4+? If not, you'll have to:
<td>
<a href="{{ route('agendarCitaPaciente', array($paciente->id, $cita->id)) }}" class="btn btn-xs btn-success">
<i class="fa fa-calendar"> Agendar</i>
</a>
</td>
As pointed by #SumanBogati, you also have a missing parenthesis.

Try changing
[$paciente->id, $cita->id ]
To
array($paciente->id, $cita->id)
It looks like you're using a PHP version that doesn't support the newer method of defining arrays.

You may forgot to write colosing parenthesis ) on this
<i class="fa fa-calendar"> Agendar</i>
//--------------------------------------missing parenthesis here----^

Related

Missing required parameters for [Route: havence.automail.edit] [URI: havence/automail/{automail}/edit]

I create edit page to edit the form. When I debug it. It's showing error which is Missing required parameters. I already try many ways but i can't solve it. Anyone can help on this?
<td class="text-right">
<a href='{{ route("email.edit",["id"=>$mailTemplate->id]) }}' class="btn btn-danger badge-pill editbtn" style="width:80px" >EDIT </a>
</td>
route file
Route::get('api/email/create', ['as' => 'email.create', 'uses' => 'Havence\AutoMailController#create']);
Route::get('automail/mail', 'Havence\AutoMailController#mail');
Route::get('automail/index',['as'=>'email.index','uses' => 'Havence\AutoMailController#index']);
Route::get('automail/edit/{id}',['as'=>'email.edit','uses' => 'Havence\AutoMailController#edit']);
Route::get('automail/delete',['as'=>'email.delete','uses' => 'Havence\AutoMailController#destroy']);
Controller
public function edit(AutoEmailTemplate $mailTemplates , $id)
{
$mailTemplates=AutoEmailTemplate::find($id);
return view('havence.marketing.edit')->with('mailTemplates', $mailTemplates);
}
You could do the following:
<td class="text-right">
<a href='{{ route("email.edit", $mailTemplate) }}' class="btn btn-danger badge-pill editbtn" style="width:80px" >EDIT </a>
</td>
The route:
Route::get('automail/edit/{id}',['as'=>'email.edit','uses' => 'Havence\AutoMailController#edit']);
Then in the controller you can get it:
public function edit(AutoEmailTemplate $mailTemplates , $id)
{
$mailTemplates=AutoEmailTemplate::find($id);
return view('havence.marketing.edit', compact('mailTemplates'));
}

how to declare variable by using the following symbol "{!!" in Laravel

I am using a ternary operator. Here is my code:
<td>
{!! $cooking->deleted_at ?
'<button type="button" data-id="{{$cooking->id}}"
data-target="#restore-CF">Enable</button>'
:'<button type="button" data-id="{{$cooking->id}}"
data-target="#exampleModal-3">Disable</button>'!!}
</td>
When I inspect by using the chrome developer tool and inspect over the following code data-id="{{$cooking->id}}" it shows <?php echo e($cooking->id); ?>,
but by inspecting I am suppose to get the value of a number i.e 12.
How to fix this error?
Remove quotes and use blade if statements
#if($cooking->trashed())
<button type="button" data-id="{{$cooking->id}}"
data-target="#restore-CF">Enable</button>
#else
<button type="button" data-id="{{$cooking->id}}"
data-target="#exampleModal-3">Disable</button>
#endif
Your qustions makes no sense
You should give a condition to check in ternary.
For your easyness, you may write
#if($cooking->deleted_at == 'your_condition_to_check_with')
<div>Your Statement</div>
#else
<div>Your Another Statement</div>
#endif
or, I think you may like to use php isset().
#if(isset($cooking->deleted_at))
Your question is very unclear though
I think it's because you are writing php and html at the same time and you are not separating the two, to separating php from html, include the php tags
<td>
<?php {!! $cooking->deleted_at ?
' ?><button type="button" data-id="<?php {{$cooking->id}} ?>"
data-target="#restore-CF">Enable</button><?php'
:'?><button type="button" data-id="<?php {{$cooking->id}} ?>"
data-target="#exampleModal-3">Disable</button><?php' !!}?> </td>
I think if you remove the mustaches on the data-id attribute it would work because you are already in a {!! !!} or better still my advice is to use blade syntax by wrapping it in an #if and #else like so
#if($cooking->deleted_at)
<button type="button" data-id="{{$cooking->id}}" data-target="#restore-CF">Enable</button>
#else
<button type="button" data-id="{{$cooking->id}}" data-target="#exampleModal-3">Disable</button>
#endif
I think this is more readable. I hope this helps.

Prevent quotation in window.open in PHP

I'm having a problem with my script. The file wont open if the filename has single quote.
Is there a way to prevent single quote in window.open?
<a class="btn btn-primary btn-xs" onclick="window.open('content_files/<?php print($contRow['cont_file']); ?>','<?php print($contRow['cont_file']); ?>','height:auto;width:auto;')">
<i class="glyphicon glyphicon-edit"></i> View
</a>
here's the output
7TATTOOED ON MY MIND CHORDS (ver 2) by D'Sound # Ultimate-Guitar
Sample Output 1.
Sample Output 2.
You should encode your filename I think:
urlencode($contRow['cont_file'])
I tried this code:
<a class="btn btn-primary btn-xs" onclick="window.open('content_files/<?php print(addslashes($contRow['cont_file'])); ?>','<?php print(addslashes($contRow['cont_file'])); ?>','height:auto;width:auto;')">
<i class="glyphicon glyphicon-edit"></i> View
</a>
and It works like a charm. thanks anyway. Credits to the one who deleted he's post but it works.

Unknown parameter format in laravel

I have this route
Route::name('recruitment.edit.profile')->get('/edit-profile/{id}', 'EmployeeController#showEditProfileForm');
having a parameter id and
this code in my blade.php
<a href="{{ route('recruitment.edit.profile', $users->id) }}" class="btn btn-success">
<i class="fa fa-edit m-right-xs"></i> Edit Profile
</a>
But when I clicked the given link I got this url http://mpci-vo.dev/recruitment/edit-profile?9 and a message Whoops, looks like something went wrong.
My question why is there a ? before 9
Change route('recruitment.edit.profile', $users->id)
to
route('recruitment.edit.profile', ['id' => $users->id])
https://laravel.com/docs/5.4/helpers#method-route

Laravel 5.3 Route in template showing Route Not Defined

i am updating my application from laravel 5.2 to 5.3. Most of the things seems to work fine.
But i dont know what is happening but when i am trying to define route in anchor tag, its not working. I have done something similar to this:
<a href="{{route('backend.pages.index')}}" class="nav-link ">
<span class="title">All Pages</span>
</a>
Its showing error Route [backend.pages.index] not defined.. Here is how the created the route.
Route::group(['middleware' => ['web']], function () {
Route::resource('backend/pages','Backend\PagesController');
});
I have a template called 'mainmenu.blade.php' in which i have use this route. This mainmenu is called in main structure through #include('layouts.backend.backendstructure.mainmenu').
Is routing method is changed in laravel 5.3? Or is there any mistake from my side?
Thank you!(Advance)
The problem here is
{{route('backend.pages.index')}}
instead use
<a href="{{route('backend/pages')}}" class="nav-link ">
<span class="title">All Pages</span>
</a>
The route is defined as backend/pages. To return view add a method in PagesController and return the view there.
Route::group(['middleware' => ['web']], function () {
Route::resource('backend/pages','Backend\PagesController#dummymethod');
});
Dummy method
public function dummymethod
{
return view('backend.pages.index');
}
Edit
I think you're looking for something like this
Route::resource('backend/pages','Backend\PagesController', ['names' => ['index' => 'backend.pages.index']]);
Check the docs here
You should write your code like this:
<a href="{{ route('backend/pages')}} " class="nav-link ">
<span class="title">All Pages</span>
</a>
or like this:
<a href="{{ url('backend/pages') }}" class="nav-link ">
<span class="title">All Pages</span>
</a>
Try:
<a href="/backend/pages" class="nav-link ">
<span class="title">All Pages</span>
</a>
https://laravel.com/docs/5.3/routing
You can try link with URL to like, I use in following manner
<a href="{{URL::to('backend/pages')}}" class="nav-link ">
<span class="title">All Pages</span>
</a>

Categories