JpDevs JpDevs - 1 year ago 114
Javascript Question

Laravel URL Generator With Angular JS Varible

I am making an application with Angular JS as frond end and Laravel as back end.

I having a list of master data table view and a delete and edit options.

<a class="resedit btn btn-sm btn-default" href="{{URL::route('edit_repair_category',[[]])}}/"><i class="icon-note"></i></a>
<a title="Delete" ng-click="deleteRow($event,,'{{URL::route('delete_repair_category')}}',currentPage)" class=" btn btn-sm btn-delete"><i class="glyphicon glyphicon-trash"></i></a>

Above I am generating URL of Edit page with Laravel URL Generator, But I want to pass the ID of the master data to fetch the data from controller.

I am using [[ ]] for Angular JS bindings.


Now I got the exception Use of undefined constant category - assumed 'category'


Route::get('edit-repair-category/{id}', ['as' => 'edit_repair_category', 'uses' => 'RepairCategoryController@editRepairCategory']);

Is there any possibilities ?

Answer Source

The reason you're getting this error is because you're mixing javascript and PHP.

The PHP portion of you code is going to be processed on the server and then passed to the browser where the javascript is then going to be processed, so as far as PHP is concerned you are trying to use a constant.

Since is just going on the end of the url you should be able to do something like:

<a class="resedit btn btn-sm btn-default" href="{{ URL::route('edit_repair_category', null) }}/@{{}}"><i class="icon-note"></i></a>

null is being used here to prevent an error being thrown.

The @ before {{}} just tells blade to treat this like a normal string and not to do anything with it (the @ symbol will be remove by blade).

Hope this helps!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download