0 experience to go until the next level!
In case you were wondering, you earn Laracasts experience when you:
Earned once you have completed your first Laracasts lesson.
Earned once you have earned your first 1000 experience points.
Earned when you have been with Laracasts for 1 year.
Earned when you have been with Laracasts for 2 years.
Earned when you have been with Laracasts for 3 years.
Earned when you have been with Laracasts for 4 years.
Earned when you have been with Laracasts for 5 years.
Earned when at least one Laracasts series has been fully completed.
Earned after your first post on the Laracasts forum.
Earned once 100 Laracasts lessons have been completed.
Earned once you receive your first "Best Reply" award on the Laracasts forum.
Earned if you are a paying Laracasts subscriber.
Earned if you have a lifetime subscription to Laracasts.
Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.
Earned once you have achieved 500 forum replies.
Earned once your experience points passes 100,000.
Earned once your experience points hits 10,000.
Earned once 1000 Laracasts lessons have been completed.
Earned once your "Best Reply" award count is 100 or more.
Earned once your experience points passes 1 million.
Earned once your experience points ranks in the top 50 of all Laracasts users.
Earned once your experience points ranks in the top 10 of all Laracasts users.
Replied to Can Not Use Auth::user() In ServiceProvider..
Here is a good blog post about this https://dcblog.dev/laravel-accessing-auth-in-service-providers
Replied to Pressing Space Bar When Watching A Video
If you press ?
when the video is in focus, it will show you all the shortcuts. That being said, the Play/Pause shortcut is not listed there, but indeed is the space
key, as long as your LAST focus was on the video. If you selected another element afterwards or clicked somewhere else on the page, the video is no longer the focused element and hence the space
will scroll the page down. Press on the video, and once it pauses try pressing space
again you'll see that the video will continue playing.
And btw, on YouTube is the same, k
letter is Play/Pause option, and not the Space button unless again the focus is on the video itself, then the Space can be used too.
Awarded Best Reply on Laravel Factory Unknown Column '0'
And how does your ProductColor
model looks like? What do you have in the $fillable
array?
Do you have name
only?
Replied to Laravel Factory Unknown Column '0'
And how does your ProductColor
model looks like? What do you have in the $fillable
array?
Do you have name
only?
Replied to Laravel Form Collective Select Option For Edit Selected
@webdevelop the value of this 'selected'
should be an ID from your User, and not selected
as a word, as that does nothing.
So if you have an option <option value="1">User Name</option>
that param should be 1
in order for that user to be selected.
Replied to How We Send Customer Data In Laravel Excel Collection Or Model
So you can pass the data in the constructor of the class:
class LeadsImport implements ToModel
{
protected $data;
public function __construct($data)
{
$this->data = $data;
}
/**
* @param array $row
*
* @return \Illuminate\Database\Eloquent\Model|null
*/
public function model(array $row)
{
// use $this->data here.
return new Lead([
'title' => $row[0],
'first_name' => $row[1],
'user_id' =>’need here user id‘
]);
}
}
of course than you need new LeadsImport($CUSTOMER_DATA)
to be passed.
Awarded Best Reply on Select Relationship Not Working Returning Null
You have to add it in the first select:
PaymentMethod::select('name', 'slug', 'payment_method_category_id')
->with(['category' => function($query){
$query->select('id', 'name')->where('status', 1);
}])->get();
In order to use eager loading using with()
the foreign key has to be selected. I noticed from the relationship that the column is named payment_method_category_id
make sure that's the right one in your payment methods table.
Replied to Laravel Helper Func
You can always ask Google as well :)
https://www.php.net/manual/en/function.htmlspecialchars-decode.php
There are examples in the documentation too.
Replied to Laravel Helper Func
with a lot of magic. I would suggest that you don't use the limit
on an HTML, it makes no sense. You can probably apply some CSS styling to hide part of it, but don't use limit
.
Replied to Laravel Helper Func
And what do you mean it does not work? Do you still see the HTML tags? Maybe your HTML gets broken because at the 100th character the closing attributes are not included.. like you have <p>asdsadas MORE THAN 100 chars
and then the </p>
is somewhere after that, of course it will not display it correctly.
Replied to Cast Date Attribute On Model Property Not Work?
@abkrim have you tried datetime
since the deleted_at
field is a datetime
type, and as the docs say:
'deleted_at' => 'datetime:d/m/Y',
https://laravel.com/docs/master/eloquent-mutators#date-casting
And the docs say this as well
When defining a date or datetime cast, you may also specify the date's format. This format will be used when the model is serialized to an array or JSON.
Note the last part, only when serialized to array or JSON.
Replied to Select Relationship Not Working Returning Null
You have to add it in the first select:
PaymentMethod::select('name', 'slug', 'payment_method_category_id')
->with(['category' => function($query){
$query->select('id', 'name')->where('status', 1);
}])->get();
In order to use eager loading using with()
the foreign key has to be selected. I noticed from the relationship that the column is named payment_method_category_id
make sure that's the right one in your payment methods table.
Replied to Select Relationship Not Working Returning Null
Add the category_id in the list too:
$query->select('id', 'name', 'payment_method_category_id')
and see if it works :)
Replied to Email Verification Not Working In Laravel Jetsream
Have you tried clicking the link in the email while you are still logged in? Are you using the same browser for both registration and the email verification?
Replied to ID Of Parent Object
@sarahs74 it is good to check the documentation from time to time, because really everything is very well written there, and that's the way to learn something. The discussion forum is good to help you in something that you are stucked at, but it is not good for learning as much, as tomorrow you will ask the same questions.
So now for your issue, that's called a Resource controller, and these are the methods generated out of it https://laravel.com/docs/master/controllers#actions-handled-by-resource-controller
and you can check that using php artisan route:list
so in your case the expected parameter will be {bill}
and in your case you are expecting property
which is null
since it is never passed.
So in case you have a select element with name="property_id"
than you can do the following in the controller:
$property = Property::findOrFail($request->property_id);
$property->bills()->create($attributes);
and remove $property
from the method signature.. I hope you follow what I am saying here, it is all in good intentions.
Replied to ID Of Parent Object
Since you are using the Route model binding, you can have the method like this:
public function create(Request $request, Property $property)
{
Bill::create([
...
'property_id' => $property->id,
]);
}
Make sure that you have property_id
in your $fillable
array of the Bill
model. Or if you have the relationships setup correctly, this would work too:
$property->bills()->create($request->only(....));
Many ways.
Replied to Laravel- Blade How To Output HTML Tag In Double Curly Braces?
Here it is: https://laravel.com/docs/8.x/blade#displaying-unescaped-data
the box below shows the issues.
Replied to Laravel- Blade How To Output HTML Tag In Double Curly Braces?
@nickywan123 you need to use {!! !!}
syntax to escape the encoding. But make sure the content that you get is safe to do so.
{!! Share::page('www.google.com')->facebook() !!}
Awarded Best Reply on Laravel Get A Json Value Which Has An Space
Replied to Laravel Get A Json Value Which Has An Space
Replied to Email Auth Body Text
Same rules apply my friend.. there is so much on the internet already, just do a quick search.. Here is a blog post as well
https://laraveldaily.com/mail-notifications-customize-templates/
and there is always the very good documentation, just spend some time reading, that's the way to learn.
Replied to Email Auth Body Text
This is the way to do it: https://stackoverflow.com/a/41401524/1457270
Replied to New Valet Install Of Jetstream Produces Class "Laravel\Fortify\Features" Not Found Error
Things I would check are
vendor/laravel/fortify/
and in there there should be Features.php
class in the src
folder.I would run php artisan serve
and open the URL there just in case.
Make sure also using valet links
your url points to the correct directory in which you are installing packages.
Nothing sarcastic here, just trying to share with you my process :)
Replied to Production.ERROR: InvalidArgumentException: Data Missing In Laravel
And you see that your $request->date_of_birth
is returning null
for some reason?
So debug your request data first and make sure you have a field with name="date_of_birth"
in your form.
Before you create you can use dd($request->all());
and inspect the data. :)
Replied to How To Get The Current Authenticated User Model Instance?
The user is already fetched, so you need to load the organization only. But anyway it will make an additional query:
return auth()->user()->load('organization');
Replied to Upgrade L7: Where Is The Symfony Console File ?
Just created a command using php artisan make:command
and this is the initial handle
method:
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
return 0;
}
Maybe the STUB is not updated for your version, but I am 100% that that was the change. So @return int
indicates what the response from the command should be.
Replied to Upgrade L7: Where Is The Symfony Console File ?
That's for custom commands that you have created. So check in your app/Console/Commands
directory, if you have one, and there are custom commands that you have created using php artisan make:command
only then you need to apply this to the handle methods in those commands. Otherwise just skip it :)
Awarded Best Reply on InvalidArgumentException: The Separation Symbol Could Not Be Found
Why do you need to transform the date twice?
And the error shows you what the issue is.. in your mutator of the model, you use this one:
Carbon::createFromFormat('d-m-Y', $value);
while the error says that the value is already in Y-m-d
format.
You could check as well if the date is already a Carbon instance then don't do anything:
public function setDateOfBirthAttribute($value)
{
if (!$value instanceof Carbon\Carbon)
{
$this->attributes['date_of_birth'] = Carbon::createFromFormat('Y-m-d', $value);
}
}
so notice the format is Y-m-d
not d-m-Y
. If you want to return it in a specific format then you use :
\Carbon\Carbon::instance(\PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($value))->format('d-m-Y');
Replied to InvalidArgumentException: The Separation Symbol Could Not Be Found
Why do you need to transform the date twice?
And the error shows you what the issue is.. in your mutator of the model, you use this one:
Carbon::createFromFormat('d-m-Y', $value);
while the error says that the value is already in Y-m-d
format.
You could check as well if the date is already a Carbon instance then don't do anything:
public function setDateOfBirthAttribute($value)
{
if (!$value instanceof Carbon\Carbon)
{
$this->attributes['date_of_birth'] = Carbon::createFromFormat('Y-m-d', $value);
}
}
so notice the format is Y-m-d
not d-m-Y
. If you want to return it in a specific format then you use :
\Carbon\Carbon::instance(\PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($value))->format('d-m-Y');
Replied to Passing An Object That Implements __toString To A Blade Component
@jacksleight I tried the same approach, created a class:
class Item {
public $id = 10;
public function __toString()
{
return 'testing';
}
}
passed it to the component, and I could still use $item->id
within it.. So can you share how does your object looks like?
Or have you tried to escape it: https://laravel.com/docs/8.x/blade#escaping-attribute-rendering
Replied to Laravel "with" Returns Null
That is because when you say type
laravel tries to match it with type_id
you need to provide the full name:
public function type() {
return $this->belongsTo(OrganizationType::class, 'organization_type_id');
}
Replied to Class Based Component Never Pass In Class
If you are not expecting any parameter within the class, you don't have to pass anything. You had something else going on for sure. I tried your code locally, it works as it should without any change.
Maybe composer dump-autoload
will auto-discover the components.
Replied to Resource Controller
@martin1182 in order to show data you need to pass id.
The route is matched to /admin-cars/{car}
and you probably are not passing anything, and it tries to return whatever you have in the index
action in your controller.
Replied to Differentiate Error List For Different Forms
You can name your error bags, and handle them in the view using their name, all very well explained in the docs here:
Awarded Best Reply on Has ->assertSet() Been Deprecated In Livewire
@jgravois no it is not, you are chaining it on the wrong method. assertOk
returns a response, so the method does not exists on that object.
Based on the docs, you need to do this:
Livewire::actingAs($this->user)
->test(CustomerWizard::class, ['code' => 'UAMI2'])
->assertSet('companyCode', 'UAMI2');
Replied to How To Display The Last 12 Months Using Carbon ?
Try this one:
$period = now()->subMonths(12)->monthsUntil(now());
$data = [];
foreach ($period as $date)
{
$data[] = [
'month' => $date->shortMonthName,
'year' => $date->year,
];
}
dd($data);
If you need them in reverse order then just use array_reverse
at the end
Replied to Has ->assertSet() Been Deprecated In Livewire
@jgravois no it is not, you are chaining it on the wrong method. assertOk
returns a response, so the method does not exists on that object.
Based on the docs, you need to do this:
Livewire::actingAs($this->user)
->test(CustomerWizard::class, ['code' => 'UAMI2'])
->assertSet('companyCode', 'UAMI2');
Replied to Very Basic Question About Routing With A Variable
And how does your index method looks like?
Like this?
public function index($subdivision)
{
$subdivisionname = str_replace('-', ' ', $subdivision);
// ...
}
Replied to Updating A Record Returns Collection::update Does Not Exist.
Your routes and form are so confusing.. first of all, on the form you are using wrong named route:
{{ route('admin.approve', $user->id)
That one calls this
Route::get('/admin/approve', [AdminUsersController::class, 'listUnapprovedUsers'])->name('admin.approve');
which is a get route, and has nothing to do with the action that you have shown from your controller.
So either the error that you are getting is not from here, or somehow the $id
is an array so that's why ::find($id)
returns a collection of many users on which you are trying to call ->update
on and hence the error.
Replied to Back()->withErrors() Vs. Redirect->route()->withErrors()
This
$this->session->flash
is what makes it go away after one request. Using $this->session->put
will work, but then you will have to be responsible for clearing it yourself, otherwise you will see error messages all the time. So i won't go that road.
Replied to Back()->withErrors() Vs. Redirect->route()->withErrors()
withErrors
adds the errors in a flash session which gets lost after the first request is performed. So essentially, back()->withErrors()
goes back one level, and that's why the flash session is still valid and you can see the errors, while once you do redirect()->route()
it goes to another action, in which the errors will be available, but then from there you are returning a different redirect or view, in which case the flash sessions is being flashed/removed. So that's why you won't be able to see the errors.
Hope this helps.
Awarded Best Reply on Livewire Displaying Custom Error
Here is how: https://laravel-livewire.com/docs/2.x/input-validation
You can add additional error messages:
$this->addError('key', 'message')
Replied to Livewire Displaying Custom Error
Here is how: https://laravel-livewire.com/docs/2.x/input-validation
You can add additional error messages:
$this->addError('key', 'message')
Awarded Best Reply on Blade Component Error When Using A For Loop
Why do you use {{}}
within blade:
@for ($i = 0; $i < $theCnt; $i++)
should do it.
Plus this:
@if ($theDivType == 'beg')
<div>
@else
</div>
@endif
does not make sense to me. You will be opening more divs than closing them I suppose, but I don't know your data, so there you go :)
Replied to Blade Component Error When Using A For Loop
Why do you use {{}}
within blade:
@for ($i = 0; $i < $theCnt; $i++)
should do it.
Plus this:
@if ($theDivType == 'beg')
<div>
@else
</div>
@endif
does not make sense to me. You will be opening more divs than closing them I suppose, but I don't know your data, so there you go :)
Awarded Best Reply on Laravel Validation For String
@himanshurajvanshi if you open the validation.php
file from your resources/lang
directory you will see this set:
'min' => [
'numeric' => 'The :attribute must be at least :min.',
'file' => 'The :attribute must be at least :min kilobytes.',
'string' => 'The :attribute must be at least :min characters.',
'array' => 'The :attribute must have at least :min items.',
],
this means that if the value entered is a string
then it will show This name should be at least 5 characters.
what do you mean by 5 number
I don't understand.
But you can override the message anytime and it will show whatever you want.
https://laravel.com/docs/master/validation#customizing-the-error-messages
Replied to Laravel Validation For String
@himanshurajvanshi if you open the validation.php
file from your resources/lang
directory you will see this set:
'min' => [
'numeric' => 'The :attribute must be at least :min.',
'file' => 'The :attribute must be at least :min kilobytes.',
'string' => 'The :attribute must be at least :min characters.',
'array' => 'The :attribute must have at least :min items.',
],
this means that if the value entered is a string
then it will show This name should be at least 5 characters.
what do you mean by 5 number
I don't understand.
But you can override the message anytime and it will show whatever you want.
https://laravel.com/docs/master/validation#customizing-the-error-messages
Awarded Best Reply on How To Translate Two Factor Authentication Default Message
This is the way to translate json strings: https://laravel.com/docs/8.x/localization#using-translation-strings-as-keys
so you just create a file within your lang
directory, for example en.json
and add
{
"The provided two factor authentication code was invalid.": "YOUR TRANSLATION HERE"
}
and it should work.
Earned once your experience points ranks in the top 10 of all Laracasts users.