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

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.

Related

Text has space to the right

I have the following code:
<div class="brm-item-name">204 Banane, Milch & Erdbeeren <button type="button" class="btn btn-info btn-xs" id="pop" data-toggle="modal" data-target="#myModal"></button></div>
"204 Banane, Milch & Erdbeeren " is pulling from database but text does not have a space in the database. The space here is giving me trouble when writing css. Do you have any suggestions on this?
You can remove it using jQuery trim().
jQuery(document).ready(function($) {
$('.brm-item-name').trim();
})

PHP Error -- Use of undefined constant x - assumed 'x'

how to get data from table and pass it in controller in json format and get those data in view using angularjs
I want to get data from json encoded variable from controller and show it to view page using angularjs
view page using angularjs
<div class="card" ng-app = "myApp">
<table class="table table-hover" ng-controller = "menuController">
<thead>
<tr>
<th>Name</th>
<th>Parent menu</th>
<th>Order</th>
<th>Status</th>
<th class="text-center">Actions</th>
</tr>
</thead>
<tbody>
<tr ng-repeat = "x in values">
<td>{{x.name}}</td>
<td>{{x.parent_name}}</td>
<td>{{x.orders}}</td>
<td>{{x.status}}</td>
<td class="text-right">
<button type="button" class="btn btn-icon-toggle"
data-toggle="tooltip" data-placement="top"
data-original-title="Edit row">
<i class="fa fa-pencil"></i>
</button>
<button type="button" class="btn btn-icon-toggle"
data-toggle="tooltip" data-placement="top"
data-original-title="Copy row">
<i class="fa fa-copy"></i>
</button>
<button type="button" class="btn btn-icon-toggle"
data-toggle="tooltip" data-placement="top"
data-original-title="Delete row">
<i class="fa fa-trash-o"></i>
</button>
</td>
</tr>
</tbody>
</table>
</div>
var app = angular.module('myApp');
app.controller('menuController',function ($scope,$http) {
$scope.values = ["Milk", "Bread", "Cheese"];
});
PHP controller code
public function getmenu(){
$records=Menu::all();
return json_encode($records);
}
route code
Route::group(['prefix'=>'admin'],function(){
Route::get('/form','HomeController#form');
});
ErrorException (E_ERROR)
Use of undefined constant x - assumed 'x' (this will throw an Error in a future version of PHP) (View:form.blade.php)
I think it might be because you are serving your view which contains the angular code with Laravel, and in the file form.blade.php you use the angular syntax, which is the same as the blade one.
To solve that, you can try to remove blade word from the view filename, so it would become form.php or (alternative way instead of modifying the filename) each time you have to print something with the JavaScript framework instead of blade, use: #{{ variableToPrint }}.
So for example, part of your loop would become:
<tr ng-repeat="x in values">
<td>#{{x.name}}</td>
<td>#{{x.parent_name}}</td>
<td>#{x.orders}}</td>
<td>#{{x.status}}</td>
<!-- ... -->
You get the error as blade uses the same syntax to evaluate and print values, so if you write: {{ x.name }} blade finds a string literal x which gets interpreted as a constant.
If you prefix the # sign, blade will recognize that as an instruction not to be parsed, but that needs to be left as it is, it would just remove the #, leaving you with the correct code for you JavaScript loop

Laravel,blade, vue.js and #if (#{{ }})

I am having a problem with variables devielve vue.js me ... I explain better
<tr
#if(#{{users.id}} != 1) // this is the error
Class="danger"
#else
class="success"
#endif
>
I can not define a #if (# {{user.id in laravel
before defined
#foreach($datos as $dato)
<tbody id={{$dato->id}}>
<tr
#if($dato->id !=1)
class="danger"
#else
Class="success"
#endif >
and it worked but I had to put a select box, and Use varaible vue.js to collect and return the data I...
excuse my English is not my mother tongue and hinders me
I do not believe you can use vuejs code (such as your #{{users.id}}) inside a laravel #if() because everything inside the #if() is being treated as PHP code. If it makes sense in your particular application, make use of vuejs's v-if implementation, such as <div v-if="users.id !== 1"> INSERT WHATEVER HERE </div>

How to control view items in codeigniter

I have CI framework and user, group permission control applied in controller,
But how can i apply restriction in some buttons, links, etc in view?
Example, below is code for new, edit, delete buttons, if i want to disble\hide this buttons
<button type="button" class="btn blue" id="new_group_showbtn"><i class="fa fa-plus"></i> New</button>
<button type="button" class="btn purple" id="edit_group_showbtn"><i class="fa fa-edit"></i> Edit</button>
<button type="button" class="btn yellow" id="delete_group_btn"><i class="fa fa-trash"></i> Delete</button>
I used control over controller as below
if($this->mylib->access('testcontrol'))
{
\\code.....
} //Access control END
How can i put such control over views? I am not echoing views, but loading pure html as view,
Can be done with passing some variables? How?
Thanks,
Try like this,
Store the user type in session on ligin(like admin, subadmin,...)
Suppose i want to show a button by name create sub admin only to user, i would do like this,
<?php if($this->session->userdata("user_type") == "admin") { ?>
<button>Add Sub Admin</button>
<?php } ?>
something like this.
Since session variables are global variables you can use them across any pages( even in views).
So while you allowing user to login,
set one session variable to appropriate value according to user type.
may be something like this
$this->session->set_userdata('privilege', 'user');
$this->session->set_userdata('privilege', 'manager');
then in the view,
you can check them like,
<html>
<body>
<div>
<?php if($this->session->userdata("privilege") == "manager") { ?>
<button type="button" class="btn yellow" id="delete_group_btn"><i class="fa fa-trash"></i> Delete</button>
<?php } ?>
</div>
.
.
.
</body>
<html>
above code only display the delete button to the user type manager.
like that you can check the condition.

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

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----^

Categories