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

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%;')) !!}

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')."')"]) !!}

Laravel no message error in Form::open

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.

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 returns htmlentities() expects parameter 1 to be string, object given

I have the following Laravel 5.1 controller function
public function editare($prod_id) {
$categorii=DB::table('categorii_produse')
->select('cat_id')
->get();
$categorie_selectata=DB::table('produse')
->leftjoin('categorii_produse','prod_cat_id','=','cat_id')
->where('prod_id','=',$prod_id)
->select('prod_cat_id')
->get();
$articole=DB::table('produse')
->leftjoin('imagini','prod_id','=','img_prod_id')
->where('prod_id','=',$prod_id)
->get();
return view ('pagini.editare',compact('categorii','categorie_selectata','articole'));
And the following line in the view which has problems
{!! Form::select('categorii',$categorii, null, ['class' => 'form-control']) !!}
The view returns the following error
htmlentities() expects parameter 1 to be string, object given
As 2nd argument you need to pass array in format value => displayed option (in your case I see you only use cat_id as both value and displayed option), so instead of:
{!! Form::select('categorii',$categorii, null, ['class' => 'form-control']) !!}
you should use:
{!! Form::select('categorii',collect($categorii)->lists('cat_id')->all(), null, ['class' => 'form-control']) !!}

Categories