adding data to #include throws an error - php

My head is aching as to what is the error in my code.
main.blade.php
Html with angular codes here....
#include('modal-template-common', ['link' => route('client.logout')])
modal-template-common.blade.php
{!! Html::link($link, 'OK', ('class'=>'btn btn-danger')) !!}
Now the problems is whenever I try to render it returns an error of
ErrorException in UrlGenerator.php line 273
angular.js:11607 Error: [$compile:tpload]
any enlightenment would greatly help me.

I am not a fan of using Html Facade.
But isn't ('class'=>'btn btn-danger') supposed to be an array ?
So, it should be like this:
{!! Html::link($link, 'OK', array('class'=>'btn btn-danger')) !!}
OR
{!! Html::link($link, 'OK', ['class'=>'btn btn-danger']) !!}
The third argument is an array. You can pass any number of key => value pairs in this array to assign other related tag's attributes. In your case, the class attribute.
For more options, refer this link

Related

php change certain rows value with a button

I have abstracts table in my database with the Abstract_Status_ID column, I am trying to create a button that changes every Status from '2' to '3'
I have tried to do this:-
My controller
public function publish($A_ID)
{
$abstracts = Project::find($A_ID);
$abstracts->Abstract_Status_ID= 3;
$abstracts->save();
return redirect('/AdvertisedProjects')->with ('success', 'Abstracts Published' );
}
my route
Route::put( '/projects', 'AbstractsController#publish');
Route::post( '/projects', 'AbstractsController#publish');
my view (projects)
Tried with the csrf token and without as eloquent docs says any post/put will be restricted without it.
#if (count ($abstracts)> 0)
#foreach ($abstracts as $abstract)
#if($abstract->Abstract_Status_ID == 2)
{!! Form::open(['action' => ['AbstractsController#publish' , $abstract->A_ID], 'method' => 'post' ]) !!}
{{ csrf_field() }}
{{Form::hidden('_method', 'PUT') }}
{{Form::Submit('Submit Changes',['class' => 'btn btn-primary'])}}
{!! Form::close() !!}
#endif
#endforeach
The error I am getting when clicking the button
(1/1) ErrorException
Missing argument 1 for App\Http\Controllers\AbstractsController::publish()
Also, the code above will show more than one button, any suggestions to make one button change all of them ?
A: If you want to have a button for each ABSTRACTS just change your route to :
Route::put( '/projects/{A_ID}', 'AbstractsController#publish');
B: If you want to have only one button that change all , you can echo their ID in hidden input then send form
so your view would be:
#if (count ($abstracts)> 0)
{!! Form::open(['action' => ['AbstractsController#publish'], 'method' => 'post' ]) !!}
{{ csrf_field() }}
{{Form::hidden('_method', 'PUT') }}
#foreach ($abstracts as $abstract)
#if($abstract->Abstract_Status_ID == 2)
{{Form::hidden('abstract_ids[]', $abstract->A_ID) }}
#endif
#endforeach
{{Form::Submit('Submit Changes',['class' => 'btn btn-primary'])}}
{!! Form::close() !!}
And Your Controller :
public function publish()
{
foreach(request('abstract_ids') as $A_ID){
$abstracts = Project::find($A_ID);
$abstracts->Abstract_Status_ID= 3;
$abstracts->save();
}
return redirect('/AdvertisedProjects')->with ('success', 'Abstracts Published' );
}
You are using form method="POST". I think it should be method="PUT".
The main problem in your code is the definition of your routes, You are passing an argument ($A_ID) to the controllers publish method,
But in your routes, you did never mention that you are passing any argument through your route. So for passing the argument, you can use {$A_ID} in your route URL.
One thing you should always remember is that you should always give your route a name and call it by using its name and route() Laravel helper method.
The benefit of using route name is that if you decide to change the URL-Structure of your route later in the development process, you'll never have to change it everywhere in your application because you did not call it by its URL.
And route name is less error prone
In total, You should define your routes like this
Route::put('projects/{A_ID}/update', 'AbstractsController#publish')->name('projects.update');
Route::post('projects/{A_ID}/post', 'AbstractsController#publish')->name('projects.store');
Then in you blade files now you can call it like
{!! Form::open(['action' => route('projects.store', $abstract->A_ID), 'method' => 'post' ]) !!}
Hope this will clarify and resolve your problem.

Can not convert table using dompdf in Laravel

I want to convert my HTML page to pdf but I can not do it. Maybe you know what I am doing wrong? Here is my code
web.php
Route::get('print/{id}',array('as'=>'htmltopdfview','uses'=>'ClientController#htmltopdfview'));
controller:
public function htmltopdfview(Request $request)
{
$products = Client::all();
view()->share('products',$products);
if($request->has('download')){
$pdf = PDF::loadView('client/print');
return $pdf->download('client/print');
}
return view('client/print' compact('client'));
}
and view:
Download PDF
<div class="panel-body">
{!! Form::open(['action' => ['ClientController#doEdit', $client->id]]) !!}
{!! Form::label('name', 'Imie i nazwisko:'); !!}
{!! Form::text('name', null, ['class' => 'form-control']) !!}
{!! Form::submit('Edit!', ['class' => 'btn btn-success']) !!}
{!! Form::close() !!}
So first you make a blade without that anchor tag, just keep plain html in your view i.e. blade.I don't get the form part but you mostly need static page for that apart from accessing the products like
{{$products->id}}
Also for accessing the data in
In controller, instead of returning view, return the below code right after the view()->share. I have mentioned below why you won't need that if condition
return $pdf->stream();
The download option will be automatically available in browsers like chrome.
Also If you aren't using any data from request,why don't you try removing it.
Also you never defined $client in that view.

Laravel & LaravelCollective HTML/Forms Error

I'm building a simple form with a username and password.
When I construct a username field like this:
{{ Form::text('username') }}
My page loads without issue. As soon as I want to define a class like this:
{{ Form::text('username', ['class' => 'awesome']) }}
I get an error, like so:
ErrorException in HtmlBuilder.php line 65:
htmlentities() expects parameter 1 to be string, array given
Haven't been able to find any info regarding this error online. These examples are taken STRAIGHT from the LaravelCollective documentation.
Any ideas? Thanks!
You should pass the class in the third parameter like so:
{{ Form::text('username', null, ['class' => 'awesome']) }}
or:
{{ Form::text('username', '', ['class' => 'awesome']) }}
The second parameter is the value field
If you are using Laravel 5 You should write like this:
{!! Form::text() !!}
Not like this:
{{ Form::text() }}
Also you have attributes array given as second parameter which is default value of this input. Please change it to:
{!! Form::text('your_name', null, ['class' => 'someclass']) !!}
Looking at the source code, the expected parameters are:
Form::text($name, $value = null, $options = [])
The second parameter is for specifying a default value for the form element. So to define a class, you should pass the array to the third parameter:
Form::text('username', null, ['class' => 'awesome'])
If you are using laravel 5.4
you shouldn't use double curly for laravel collective html form like this
{{ Form::() }}
try this instead
{!! Form::text('username', $value = null, ['class' => 'awesome']) !!}

Laravel 5 binding value in bootstrap-slider in edit/Patch

I'm implementing bootstrap-slider in my CRUD, I have implemented it successfully in Create, the problem is when I try to edit it,
I want to get the current value from the Model. Idk how to do this.
This is for PATCH.
<div class="form-group">
<h3 class='box-title text-info'>Percentage</h3>
{!! Form::input('text','percentage',null,['id'=>'ex8', 'data-slider-id'=>'ex1Slider', 'data-slider-min'=>'0', 'data-slider-max'=>'100', 'data-slider-step'=>'5', 'data-slider-value'=>'50']) !!}
</div>
In your form instead of creating a new form. You will bind the form to the model.
{!! Form::model('modelname', [options here] !!}
All the fields will math the model's property values.
Edit
Here is an example
You must used something like this to create a EDIT FORM
{{ Form::model($smartphones, ['method' => 'PATCH', 'url' => 'smartphones/'.$smartphones->id]) }}
You get by using $(your_model)['inputID']...You can use in "data-slider-value"... Something like this
{{ Form::input('text','mem_ram', null, ['id' => 'mem_ram', 'data-slider-value'=>$smartphones['mem_ram']]) }}

laravel populate select box

I have seen similar questions asked before, but was unable to find a solution to my problem. So I have a ClientController and within it this function
public function edit(Client $client)
{
return view('clients.edit', compact('client'));
}
So that passes the client object to my edit view. This view is pretty much the following
{!! Form::model($client, ['method' => 'PATCH', 'route' => ['clients.update', $client->slug]]) !!}
#include('clients/partials/_form', ['submit_text' => 'Edit Client'])
{!! Form::close() !!}
So it is using a partial for the form. At the moment, the partial looks like so
<div class="form-group">
{!! Form::label('clientName', 'Client Name:') !!}
{!! Form::text('clientName') !!}
</div>
<div class="form-group">
{!! Form::label('clientStatus', 'Client Status:') !!}
{!! Form::select('clientStatus') !!}
</div>
When I visit the edit page for a client, I can see the form. The clientName is populated with the clientName value. The clientStatus is populated if I put it as a text input, but I cant get it to populate within a select as shown above. Furthermore, clientStatus can either be New or Existing. I need the select box to be pre-populated with the status of the client that is being edited, but I need the other option available within the select as well. So if the clientStatus is New, New should be pre-selected within the select box and if I open the select, Existing should be the other option.
What would be the best way to achieve this?
Thanks
Modify your select to include an array of the possible values.
Basic Select - Label is value
{!! Form::select('clientStatus',['New','Existing']) !!}
Key Value Select - Key is value
{!! Form::select('clientStatus',[ 1 => 'New', 2 => 'Existing']) !!}
Form model will then set the value in the select to the one in the model.
More information see the docs.

Categories