App doesn't read {{ on views - php

I'm trying to create a form to delete a row in my db:
#foreach ($CostStatuses as $CostStatus)
<tr>
<td class="table-text">
<div>
<a href="/costStatus/{{ $CostStatus->id }}/edit">
{{ $CostStatus->status_name }}
</a>
</div>
</td>
<td>
{{ Form::open(array('url' => 'CostStatus/' . $CostStatus->id, 'class' => 'pull-right')) }}
{{ Form::hidden('_method', 'DELETE') }}
{{ Form::submit('Delete this Nerd', array('class' => 'btn btn-warning')) }}
{{ Form::close() }}
</td>
</tr>
#endforeach
But the html shows the form inside the {{ }} as a text to the user.

That's because {{}} does not execute the contents inside. Use {!! !!}.

LAready fixed:
Just change {{ for {!!.

Related

laravel 5 delete method. always MethodNotAllowedHttpException in RouteCollection.php line 233:

This is my route
Route::delete('/customer_page/summary/{id}', 'ReservationController#delete_cart');
My controller function
public function delete_cart($id)
{
cart::findOrFail($id)->delete();
return redirect('/customer_page/summary');
}
My form
#foreach($cart as $key => $val)
<tr>
<td>{{ $val->room_type }}</td>
<td>{{ $val->number_of_rooms }}</td>
<td>{{ $val->price }}</td>
<td>
<form action="/customer_page/summary/{{ $val->id }}" method="post">
{{ csrf_field() }}
<input type="hidden" name="_method" value="DELETE" />
<button type="submit" class="btn waves-effect red"><i class="material-icons">delete</i>delete</button>
</form>
</td>
</tr>
#endforeach
I don't know why I always keep getting that error
You need to set your method="POST" on your form, then inside of the form, use Laravel's method_field() helper: {{ method_field('DELETE') }}. Do not attempt to set your method to delete directly.
The other answer using the form helper package form laravel-collective will work fine too, but that's not included by default in Laravel anymore, so I thought it prudent to outline how to achieve this using raw HTML.
Do the following(RESTFUL)
Route::resource('reservations', 'ReservationController');
OR(NON RESTFUL)
Route::delete('delete/{id}',array('uses' => 'ReservationController#destroy', 'as' => 'My.route'));
Controller
public function destroy($id)
{
$item = Reservation::findOrFail($id);
$item->delete();
}
View
#foreach($reservations as $item)
<tr>
<td>{{ $item->description }}</td>
<td>
{{ Form::open(['method' => 'DELETE', 'route' => 'reservations.destroy', $item->id]) }}
{{ Form::hidden('id', $item->id) }}
{{ Form::submit('Delete', ['class' => 'btn btn-danger']) }}
{{ Form::close() }}
</td>
</tr>
#endforeach
OR (for non restful)
{{ Form::open(['route' => ['My.route', $value->id], 'method' => 'delete']) }}
<button type="submit">Delete</button>
{{ Form::close() }}
If you are using the below
{!! Form::model($user,
['method' => 'DELETE',
'route' => ['users.destroy', $user->id],
]) !!}
{{ method_field('DELETE') }}
// then you form goes here
{{ method_field('DELETE') }}
{!! Form::close() !!}
You need to change method on form, from POST to DELETE
You see on route you have defined as DELETE:
Route::delete('/customer_page/summary/{id}', 'ReservationController#delete_cart');

Issue with resizing fields of form under symfony 3

I have a problem with resizing the fields I've generated with symfony, my fields take the whole width of the page. Here is my code:
Controller :
$user= new User();
$form=$this->CreateFormBuilder($user)
->add("firstName",TextType::class)
->add("lastName",TextType::class)
->add("login",TextType::class)
->add("password",PasswordType::class)
->add("tel",TextType::class)
->add("email",TextType::class)
->add("address",TextType::class)
->add("send",SubmitType::class)
-> getForm();
$form->handleRequest($req);
if($form->isValid())
{
$em=$this->getDoctrine()->getManager();
$em->persist($user);
$em->flush();
}
return $this->render('eplateformeBundle:Default:register.html.twig',['form'=>$form->createView()]);
The view :
<div class="well">
{{ form_start(form ) }}
{{ form_errors(form) }}
{{ form_row(form.firstName) }}
{{ form_row(form.lastName) }}
{{ form_row(form.login) }}
{{ form_row(form.password) }}
{{ form_row(form.tel) }}
{{ form_row(form.email) }}
{{ form_row(form.address) }}
{{ form_widget(form.send, {'attr': {'class': 'btn btn-primary'}}) }}
{{ form_rest(form) }}
{{ form_end(form) }}
</div>
You can transfer own class to inputs fields like this:
<div class="well">
{{ form_start(form ) }}
{{ form_errors(form) }}
{{ form_row(form.firstName,{'attr':{'class':'your own class''}}) }}
{{ form_row(form.lastName,{'attr':{'class':'your own class''}}) }}
{{ form_row(form.login,{'attr':{'class':'your own class''}}) }}
{{ form_row(form.password,{'attr':{'class':'your own class''}}) }}
{{ form_row(form.tel,{'attr':{'class':'your own class''}}) }}
{{ form_row(form.email,{'attr':{'class':'your own class''}}) }}
{{ form_row(form.address,{'attr':{'class':'your own class''}}) }}
{{ form_widget(form.send, {'attr': {'class': 'btn btn-primary'}}) }}
{{ form_rest(form) }}
{{ form_end(form) }}
</div>

How to customize FOSUserBundle forms

I have below problem with FOSUserBundle customization.
I was overwritten FOSUser register form, then I changed register_content from
{{ form_widget(form) }}
to:
<div class="col-md-6">
{{ form_label(form.firstname) }}
{{ form_errors(form.firstname) }}
{{ form_widget(form.firstname) }}
{{ form_label(form.lastname) }}
{{ form_errors(form.lastname) }}
{{ form_widget(form.lastname) }}
</div>
<div class="col-md-6">
{{ form_label(form.email) }}
{{ form_errors(form.email) }}
{{ form_widget(form.email) }}
{{ form_label(form.plainPassword) }}
{{ form_errors(form.plainPassword) }}
{{ form_widget(form.plainPassword) }}
{{ form_label(form.plainPassword.second) }}
{{ form_errors(form.plainPassword.second) }}
{{ form_widget(form.plainPassword.second) }}
</div>
But, when I was went to the browser, I got it:
bad form render
The form renders incorrectly. How I can repair this?
try with this
{{ form_label(form.plainPassword.first) }}
{{ form_errors(form.plainPassword.first) }}
{{ form_widget(form.plainPassword.first) }}
{{ form_label(form.plainPassword.second) }}
{{ form_errors(form.plainPassword.second) }}
{{ form_widget(form.plainPassword.second) }}

wrong parameter returning to controller

I'm running on Lavarel and crossing this code:
{{ link_to_route('users.edit', 'Edit', array($user->id), array('class' => 'btn btn-info')) }}
This is the ./app/views/users/edit.blade.php
#extends('users.scaffold')
#section('main')
<h1>Edit User</h1>
{{ Form::model($user, array('method' => 'patch', 'route' => array('users.update', $user->id))) }}
<ul>
<li>
{{ Form::label('username', 'Username: ') }}
{{ Form::text('username') }}
</li>
<li>
{{ Form::label('password', 'Password: ') }}
{{ Form::text('password') }}
</li>
<li>
{{ Form::label('email', 'Email: ') }}
{{ Form::text('email') }}
</li>
<li>
{{ Form::label('phone', 'Phone: ') }}
{{ Form::text('phone') }}
</li>
<li>
{{ Form::label('name', 'Name: ') }}
{{ Form::text('name') }}
</li>
<li>
{{ Form::submit('Update', array('class' => 'btn btn-info')) }}
{{ link_to_route('users.show', 'Cancel', $user->id, array('class' => 'btn')) }}
</li>
</ul>
{{ Form::close() }}
#if (($errors->any()))
<ul>
{{ implode('', $errors->all('<li class="error">:message</li>')) }}
</ul>
#endif
#stop
The above code in the template file edit.blade.php, and when users click to the Edit button, it should pass the user id $user->id to the controller UsersController#edit where edit action is defined,
public function edit($id)
{
$user = User::find($id);
if(is_null($user)) {
return 'Not found: '.$id;
// return Redirect::route('users.index');
}
return Redirect::route('users.edit', compact('user'));
}
The problem here is that $id is not what passing from link_to_route() function.
Can anyone help me find out where the problem is? Thanks.
Here the DOM result:
Edit
This is the routes.php
Route::resource('users', 'UsersController');
This is result after clicking Edit button:
Not found: {"id":1,"username":"john","password":"johndoe","email":"johndoe#gmail.com","phone":"123456","name":"John","created_at":"2013-06-07 08:13:28","updated_at":"2013-06-07 08:13:28"}
Based upon your info - it looks like the problem is not with link_to_route() - you can see the error is further in your code.
It looks like you have bound the route to the model, so in your edit function $id is actually the $user already populated from the database.
You can tell that is the case - because your custom "not found" error gives you the user data.
If you change your code to this - does it work?
public function edit(User $user)
{
return Redirect::route('users.edit', compact('user'));
}

BootStrap in laravel blade templateEngine

i'm using Blade template Engine in Laravel. and i want to desing forms with twitter bootstrap.
My sample Form
#section('content')
<div style='margin:20px auto;height:100px;width:300px;background-color: #fff;line-height: 1.5px'>
{{ Form::open(array('route'=>'auth', 'method'=>'post')) }}
{{ Form::text('username', Input::old('username'), array('placeholder'=>'Username', 'id'=>'username')) }}
{{ Form::password('password', array('placeholder'=>'Password', 'id'=>'password')) }}
{{ Form::submit('Login', array('id'=>'submit')) }}
{{ Form::close() }}
</div>
#stop
in this sample. how to setting that for bootstrap?
To apply the Bootstrap style to your forms, you need to pass the class "form-control" into your blade:
{{ Form::text('username', Input::old('username'), array('placeholder'=>'Username', 'id'=>'username', 'class' => 'form-control')) }}
Styling laravel/blade forms with bootstrap:
["class"=>"form-control"]

Categories