Laravel no message error in Form::open - php

Hi I am using Laravel version 5.6 and got No message in a view using a Form::open with the code below
{!! Form::open(['route' => array('admin.msgs.send', 'id'=>$user->id)]) !!}
But I got the route on registred on my file, just like this:
Route::get('msgs/send/{id}', ['as'=>'admin.msgs.send', 'uses'=>'MsgsController#send']);
Some one knows what is wrong?

Try:
{!! Form::open(['route' => ['route.name', $user->id]]) !!}
or:
{!! Form::open(['route' => ['route.name', ['id' => $user->id]]]) !!}

The problem was the type of the method, I realized the route was registred as GET and not as POST, which is the type of a form.

Related

How to put translation into array in Laravel Form?

I need to have a prompt box which would be set through the key 'onsubmit' in Form array. This version works:
{!! Form::model($currentUser,
['route' => ['post.users.current.account.index', $currentUser->id],
'onsubmit' => 'return confirm(\'Are you sure?\')']) !!}
But I am unable to inject a translation into it to make it work. So far I tried this without success:
{!! Form::model($currentUser,
['route' => ['post.users.current.account.index', $currentUser->id],
'onsubmit' => 'return confirm(\''.{{trans('Users::users.current.account.index.box.confirm')}}.'\')']) !!}
Is there a way to concatenate function output inside the array value?
Please Try
{!! Form::model($currentUser,
['route' => ['post.users.current.account.index', $currentUser->id],
'onsubmit' => "return confirm('".trans('Users::users.current.account.index.box.confirm')."')"]) !!}

isset for form builder

I am using form builder and I share one form for edit and crete page so there are some variables I don't want to use.
I know that:
{!! Form::text('name', isset($admin_link->name) ? $admin_link->name : null, ['class' => 'form-control']) !!}
would work but I do not consider it the best way. Is there any way to use something else like isset for form builder?
I sent the model to the blade with values what caused autocomplete of the input what is probably what I have been looking for:
{!! Form::model( $admin_link, ['route' => ['admin.links.update', $admin_link->id], 'method' => 'post', 'class' => 'main_link_form']) !!}

How to set correct URL in Laravel?

I use Laravel 5 and have the following routing configuration:
$router->resource('restaurants', 'Registration');
And method:
public function store(Auth $userModel, Request $request){
});
In my view file I specifed form like:
{!! Form::open(array('url' => 'restaurants.store')) !!}
When I submit form I am transfered on the address: restaurants.store and get error:
Sorry, the page you are looking for could not be found.
You can use the url syntax which needs a slash like so:
{!! Form::open(array('url' => 'restaurants/store')) !!}
Or the route syntax (if you've got the route set up) like so:
{!! Form::open(array('route' => 'restaurants.store')) !!}
{!! Form::open(array('url' => route('restaurants.store'))) !!}
change {!! Form::open(array('url' => 'restaurants.store')) !!} with {!! Form::open(array('route' => 'restaurants.store')) !!} and since you use restful, in your routes.php $router->resource('restaurants', 'RestaurantsController');

Laravel 5.2 form url using named route

Using Laravel 5.2, I have a form in one of my Blade templates which I want to open and have it point to a named route, which includes a variable.
Essentially I want the resolved form command to open as follows:;
<form method="POST" action="http://my.url.com/dash/varname">
</form>
So, using Blade, I want to open the form using the named route so if this changes in my routes.php, the form will still work.
I am trying to do it as follows:
{!! Form::open(['url' => "route('dashboard.setup', ['var' => 'varname'])", 'method' => 'post']) !!}
{!! Form::close() !!}
also
{!! Form::open(['route' => "dashboard.setup, ['var' => 'varname']", 'method' => 'post']) !!}
{!! Form::close() !!}
But this does not work. How can I do this and avoid hard coding the url and variable? Thanks!
Try like this. By default, a POST method will be assumed;
{!! Form::open(array('route' => array('dashboard.setup', 'varname'))) !!}
{!! Form::close() !!}
Try the following:
{!! Form::open(array('route' => array('dashboard.setup', 'varname'), 'method' => 'post')) !!}
{!! Form::close() !!}

Laravel not letting me add styles to my Form::text()

This is my code for the form builder, and when I remove the array from the text() everything is fine, but when I add it I get this error
ErrorException in helpers.php line 454: htmlentities() expects
parameter 1 to be string, array given (View:
/Users/samir/Sites/elicant/resources/views/pages/classes.blade.php)
{!! Form::open(array("url" => 'addClass', "method" => 'post')) !!}
{!! Form::text('classname', array('style' => 'width:80%;')) !!}
{!! Form::text('classcolour') !!}
{!! Form::submit("Add") !!}
{!! Form::close() !!}
What have I done wrong?
Form::text has 3 parameters: $name, $value, array $options = array()
So to make your code working:
{!! Form::text('classname', null, array('style' => 'width:80%;')) !!}

Categories