laravel blade #include with localised variable - laravel

I have this code:
#include('admin.members.members_form', ['submitButtonText' => '__('member.edit')'])
and in the admin.members.members_form:
{!! Form::submit($submitButtonText, ['class' => '"btn btn-primary"']) !!}
THe inclusion is not working (with this version I have an error with single quote, I tryied with \'member.edit\' have no error but whe button with text __('member.edit')

you can do like that (without quote)
#include('admin.members.members_form', ['submitButtonText' => __('member.edit')])

Related

Blade view for rich text field on description tag

I'm using voyager in a laravel 7 shopping app for the description of all products.
I want to output the field for the description of the product
#section('description', {!! $item->description !!} )
and
for the facebook share = og:description" content="{!! $item->description !!}">
When I use {!! $item->description !!} in the body, no problem. But in the tag the output always read the p tag and all style form the description.
The weird thing is it's working find on localhost but not on the server. I tried various combination of solution with the same result. I feel there's a quick or maybe it's just not possible?
try html_entity_decode() ref link https://www.php.net/manual/en/function.html-entity-decode.php
{!! $item->description !!}
to
{!! html_entity_decode($item->description) !!} // it will render html
If you are using laravel 7/8 you can create a blade component then you can simple call
<x-editor :content="$description></x-editor>
check out this laravel docs
try this:
{{strip_tags(trim($item->description)}}

Laravel & LaravelCollective The first argument should be either a string or an integer

Im trying to create DELETE button in my Laravel CRUD app. and have an error:
(2/2) ErrorException array_key_exists(): The first argument should be either a string or an integer
My view:
{{!!Form::open(['action' => ['CompanyController#update', $company->id], 'method' => 'PUT'])!!}}
{{Form::input('Delete',['class'=>'btn btn-danger'])}}
{{!!Form::close()!!}}
I'm using Laravel Collective documentation and it says I can use:
Form::open(['action' => ['Controller#method', $user]])
But whats wrong with my code?
You must provide the key. Collective won't try to guess the key name, as we are used to on Laravel.
Form::open(['action' => ['Controller#method', $user->id]])
The piece of code above shows how to provide the key: $user->id

laravel form model binding and vuejs

I am having an issue while binding from data with my model. When I load the edit page for editing a resource, I can see the input value in the input but it disappears asap since its binded to the vuejs.
Here is my vuejs data
data: {
form: new Form({
title: '',
language: [],
poster: ''
})
},
and my inputs are like this
{!! Form::model($movie, ['class' => 'form-horizontal', '#submit.prevent' => 'form.updateMovie', 'id' => 'update-movie-form', 'files' => true, '#keydown' => 'form.errors.clear($event.target.name)']) !!}
....
{!! Form::text('title', 'movie title', ['class' => 'form-control', 'id' => 'title', 'v-model' => 'form.title']) !!}
....
{!! Form::close() !!}
How I can get around this issue?
I've had exactly the same issue today.
The Vue.js version 1 allows us to provide initial values to the v-model via value attribute, but this functionality was deprecated on the version 2.0.
Migration guide says:
v-model no longer cares about the initial value of an inline value attribute. For predictability, it will instead always treat the Vue instance data as the source of truth.
Credit where credit due: https://www.npmjs.com/package/vue-data-scooper
The author of that plugin (and quote) identifies a change in Vue.js, and wrote the vue-data-scooper plugin as a work-around (to restore the former functionality).
I'm now using the plugin myself (following the instructions on the above link) and can confirm it "resolves" the issue you're seeing.
I don't wish to duplicate the existing instructions found in the plugin's documentation, but I didn't find they aligned precisely with the Laravel installation I was using (v5.4).
Specifically I installed the plugin...
npm install vue-data-scooper
...then patched my app.js (which is extremely minimal in my case)...
require('./bootstrap');
window.Vue = require('vue');
import VueDataScooper from "vue-data-scooper"
Vue.use(VueDataScooper);
...and dropped the data: {...} declaration from my new Vue(...) declarations (allowing the plugin to sort it out using initial data).

Error while using yield in Form:text value

1) Making CRUD so wanted to use yield in value in Form:text to load the values
{!! Form::Text('employeeName_txt',
'#yield('editEmployeeName')',
array('class' => 'form-control','placeholder'=>'Employee Name')) !!}
Getting error
FatalErrorException in 2168be22f5078758fb418696bf6815fc3ab642a4.php line 59:
syntax error, unexpected 'editEmployeeName' (T_STRING)
Can anyone please help what is wrong in this
& also
2) Which is the best method for CRUD
Creating Edit page differently & extending it with create page and yield or section the values
Or in create page only, with the use of if else condition do the coding eg: if route name contains edit then method= put ,delete button show etc.
Try using this
{!! Form::Text('employeeName_txt',"yield('editEmployeeName')", array('class' => 'form-control','placeholder'=>'Employee Name')) !!}

laravel upload file - Call to a member function getClientOriginalName

I have a strange problem today because the code that I will show you is to upload and move an image in a database + uploads directory in my laravel.
The last projects worked but today with laravel 5.4 the code doesn't work anymore and when I want to upload a new image I get an exception
with this line:
Call to a member function getClientOriginalName() on null
Line : $licencie_structure->lb_photo = $request->file('lb_photo')->getClientOriginalName();
Here my blade line to upload the file :
<div class="form-group">
<label>Select a picture : </label>
{!! Form::file('lb_photo' , ['class' => 'form-control', 'placeholder' => 'Photo']) !!}
</div>
Does someone have an idea why I get an exception : Call to a member function getClientOriginalName() on null?
Thanks a lot in advance friends!
This is returning null, meaning it's not in the request object.
$request->file('lb_photo')
Is this form actually sending the upload? Did you forget to add enctype='multipart/form-data' to the form? Is the name correct?
Check the output of $request->all().

Resources