Member Since 3 Years Ago
4,780 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.
Awarded Best Reply on Laravel 8 CORS For Subdomain API
'allowed_origins' => ['*.app.test'],
api/*
, maybe, you could use:'paths' => ['*'],
Indeed, if you had API routes such as POST http://graphql.app.test/api/posts
and POST http://graphql.app.test/api/comments
, and all other API routes were starting with api/
as well, it would make sense to use api/*
.
I hope this helps.
Replied to How To Call An Order Item Because The Data Is Not Single
By call an order item
, do you mean access an order item
? Or do you want to sort the items ?
Replied to [PostController] Does Not Exist.
@cbcw Good catch, thanks for letting me know. I have corrected the typo ;)
Replied to Search Not Work Laravel 8x + Livewire
Replied to Search Not Work Laravel 8x + Livewire
I guess you should replace updateQuery()
with updatedQuery()
Source:
updatedFoo
example: https://laravel-livewire.com/docs/2.x/lifecycle-hooks
Awarded Best Reply on Undefined Property: App\Imports\FirstLeaveSheetImport::$getStaffId
In your code getStaffId
is a method, so in your $leave
array, you should use $this->getStaffId()
with the parenthesis at the end. Otherwise, it would look for a getStaffId
property and none is defined. The only defined property is $staffid
.
Replied to Undefined Property: App\Imports\FirstLeaveSheetImport::$getStaffId
In your code getStaffId
is a method, so in your $leave
array, you should use $this->getStaffId()
with the parenthesis at the end. Otherwise, it would look for a getStaffId
property and none is defined. The only defined property is $staffid
.
Awarded Best Reply on Undefined Variable: Post (View: /.....resources/views/error.blade.php)
Since you specify in the component that you edit a task: public function edit(Task $task)
, maybe you should use $task
instead of $post
. Your code would be:
<button wire:click="edit({{ $task->id }})" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">Edit</button>
Replied to Undefined Variable: Post (View: /.....resources/views/error.blade.php)
Since you specify in the component that you edit a task: public function edit(Task $task)
, maybe you should use $task
instead of $post
. Your code would be:
<button wire:click="edit({{ $task->id }})" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">Edit</button>
Awarded Best Reply on Looking For A Recommendation For A No-captcha For Laravel 7
Maybe, you can check this one out then: https://github.com/google/ReCAPTCHA
Besides, it's the Google one and it's a PHP one, so it's not specific to Laravel
Here is a video: https://www.youtube.com/watch?v=mE6NU5ABel4
Awarded Best Reply on Meaning And Using Of First()
They will give you the same result but they work differently:
$settings = Setting::first();
will return directly the first record from the database running : select * from settings limit 1;
$settings = Setting::all()->first();
will call all
that returns a collection after running: select * from settings;
, then it will call first
to take the first element in the collection: https://laravel.com/docs/8.x/collections#method-firstYou should use the first one.
Source: I used https://laravel.com/docs/8.x/database#listening-for-query-events to confirm my first thought.
toSql
gave a different result in this specific use case, it gaveselect * from settings
in both cases
Replied to Issue Grabbing All Emails From DOM String With Match And Regex
You shouldn't put your Regex between double quotes, here is how it should be:
var emailRegex = new RegExp(/([\s]*)([_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*([ ]+|)@([ ]+|)([a-zA-Z0-9-]+\.)+([a-zA-Z]{2,}))([\s]*)/i, "g");
Awarded Best Reply on One To Many Relationship - Polymorphic Or Regular?
Do you use https://github.com/spatie/laravel-activitylog ?
Since you use a One to Many, I would expect department
instead of departments
in your with
call. I assume you have a method department
using belongsTo
in your Order model.
Besides, just to confirm it, you use orderBy
with variables, I would call the second variable$direction
. Indeed, it may be confusing in the future. As you may know, orderBy
is used like this: orderBy('name', 'desc')
Replied to One To Many Relationship - Polymorphic Or Regular?
Do you use https://github.com/spatie/laravel-activitylog ?
Since you use a One to Many, I would expect department
instead of departments
in your with
call. I assume you have a method department
using belongsTo
in your Order model.
Besides, just to confirm it, you use orderBy
with variables, I would call the second variable$direction
. Indeed, it may be confusing in the future. As you may know, orderBy
is used like this: orderBy('name', 'desc')
Replied to Get Array Keys Php/ Laravel
You're welcome, the display might be confusing at the beginning :)
Awarded Best Reply on Get Array Keys Php/ Laravel
Actually, you had the right result, it's just formatted in a different way.
array:2 [▼
0 => "date"
1 => "user_id"
]
is equivalent to:
[
"date",
"user_id"
]
Replied to Meaning And Using Of First()
They will give you the same result but they work differently:
$settings = Setting::first();
will return directly the first record from the database running : select * from settings limit 1;
$settings = Setting::all()->first();
will call all
that returns a collection after running: select * from settings;
, then it will call first
to take the first element in the collection: https://laravel.com/docs/8.x/collections#method-firstYou should use the first one.
Source: I used https://laravel.com/docs/8.x/database#listening-for-query-events to confirm my first thought.
toSql
gave a different result in this specific use case, it gaveselect * from settings
in both cases
Replied to One To Many Relationship - Polymorphic Or Regular?
From the information I have so far, I would reach for a Many to Many relationship. Indeed, we can say that a department has many orders and an order belongs to many departments.
Imagine you have a specific order Order, let's call it O.
The order goes from department A to C:
Now, imagine that you have a One to Many relationship, so, the order belongs to C at the end. But, what if you want to know if it has been processed by A. That's where the Many to Many is handy, you can still get a record that says that it has been processed by A, I'm referring to the pivot table record. Besides, you can put a status flag and for example, a completed_at date which is null by default.
Replied to One To Many Relationship - Polymorphic Or Regular?
I would need to understand the Order business logic. What is the life cycle of an order ? I guess it's initiated by a department but you said that a department should be able to pass it to another one. Could you give me an example ?
An example like the following would be perfect: "IT department makes 5 orders to buy laptops ... " :)
Replied to One To Many Relationship - Polymorphic Or Regular?
From what I understand, I would use a regular one.
I am assuming you have the following tables:
And I am assuming that all departments have the same attributes except for the type: "Sales", "HR", ... So, with a where
constraint, you can filter departments and you can get all employees for a specific type of department. As for the orders, it's pretty similar, you can get all orders passed from a specific department and from one to another.
I would have reached for polymorphism in a scenario in which a user works in a Company or a School and each one of them is completely different and each correponding table has its own set of attributes in the database.
Replied to How To Make If Condition In Blade
I think you should use an @if statement like this:
@if ($post->created_at->format('Y-m-d') === date('Y-m-d'))
<span style="color: #ff3c00" class="blink_me"><i>BARU</i></span>
@endif
date
is a PHP function : https://www.php.net/manual/fr/function.date.php
When you call it like this: date('Y-m-d')
, it returns today's date formatted with Y-m-d and you format your article created_at date the same way
Replied to Get Array Keys Php/ Laravel
I've just installed it and tested it a bit, I love it. Thanks a lot :)
Replied to Get Array Keys Php/ Laravel
Actually, you had the right result, it's just formatted in a different way.
array:2 [▼
0 => "date"
1 => "user_id"
]
is equivalent to:
[
"date",
"user_id"
]
I am surprised the following configuration keys are within an array:
'date_format' => 'd/m/Y',
'date_format_js' => 'dd/mm/yy',
You should try to put them outside of the array and remove the array.
Replied to Upload Multiple Images
I would recommend to take a look at this tutorial, it looks pretty well explained: https://www.itsolutionstuff.com/post/laravel-7-multiple-file-upload-tutorialexample.html
You should adapt it to your images use case as you did in your HTML with:
accept="image/png, image/jpeg"
and modify the controller validation part:
'images.*' => 'mimes:jpeg,png'
And other details such as your images storage folder.
Replied to Driver [] Is Not Supported. When I Upload A Pic
At first sight, it might be related to the configuration file filesystems.php
. I think this can help you: https://laracasts.com/discuss/channels/laravel/driver-is-not-supported-1
Replied to Can Modify Mutli Route GET With One Command
@snapey Yeah, having 2 routes with the same endpoint is clearly irrelevant. Just wanted to point out that detail since we were giving different explanations. When I think about it, this might have been confusing.
Replied to Can Modify Mutli Route GET With One Command
@snapey I have just tested using the same endpoint and it's the second one that is used. I guess you were thinking about the typical use case posts/{post}
vs posts/create
Replied to Can Modify Mutli Route GET With One Command
Actually, if you have 2 routes with the same endpoint, the second one overwrites the first. So, the agenda method is going to be called but the index method never. So, the code is not useful.
However, maybe Route::resource
can help you sometimes to avoid to have a lot of route declarations in your route file.
Awarded Best Reply on Sort Messages By Date
Maybe, you can do this in your controller:
$msgs = Message::where('de_user_id', $request->user()->id)->orWhere('para_user_id', $request->user()->id)->get()
// ...
You'll have both type of messages sent and received. Then you'll have to return only $msgs
and loop through msgs
only in Vue, no need to have 2 loops. Then, you can check at each iteration if the id is equal to the one of the user so that you can put the message to the left or to the right.
Replied to Sort Messages By Date
Maybe, you can do this in your controller:
$msgs = Message::where('de_user_id', $request->user()->id)->orWhere('para_user_id', $request->user()->id)->get()
// ...
You'll have both type of messages sent and received. Then you'll have to return only $msgs
and loop through msgs
only in Vue, no need to have 2 loops. Then, you can check at each iteration if the id is equal to the one of the user so that you can put the message to the left or to the right.
Replied to Use Data From Config/app In Javascript File
@msslgomez You're welcome. Actually, the variable can have any name but I think App
is pretty common
Awarded Best Reply on Use Data From Config/app In Javascript File
In i18n.js
, you can use window.App.locale
if you use the example above. In this case, App
is a global variable. Since it is pretty small, you can put it in your layout master file in the HTML header and it would be available in any JavaScript file.
Is it not what you need ?
Replied to Post Request Return 302
@snapey yeah totally, I focused entirely in the standard non ajax way. You are right, if it's an ajax call, then just return;
. Otherwise, the full HTML is returned and it's not useful at all.
Awarded Best Reply on Base Table Or View Not Found: 1146 Table 'web.papans' Doesn't Exist (SQL: Select Count(*) As Aggregate From `papans
@hendrasaputra2323 By default, in Laravel, for a Papan
model, the corresponding table should bepapans
.
Usually, people leave it in the plural form but you can update the table associated with a model in your Papan Model file:
protected $table = 'papan';
https://laravel.com/docs/8.x/eloquent#eloquent-model-conventions
@hendrasaputra2323 By default, in Laravel, for a Papan
model, the corresponding table should bepapans
.
Usually, people leave it in the plural form but you can update the table associated with a model in your Papan Model file:
protected $table = 'papan';
https://laravel.com/docs/8.x/eloquent#eloquent-model-conventions
In your database/migrations
folder, do you have a file called something like: ...create_papans_table.php
?
Please run php artisan migrate
if you have not so that your latest migrations are taken into account.
Replied to Post Request Return 302
First of all, you probably know it, the proper way is with return back();
Here is the back
helper definition in the framework:
* @return \Illuminate\Http\RedirectResponse
*/
function back($status = 302, $headers = [], $fallback = false)
{
return app('redirect')->back($status, $headers, $fallback);
}
It returns a RedirectResponse
and by default it uses 302
. Now, in practice, after the 302
, you'll get a 200
if the target route exists and everything goes well, since it's a redirection.
When you don't use return back();
, it's as if you do:
back();
return;
The RedirectResponse
object is built at some point with back()
but never returned and by default, when there is no return, it's as if the method ends with return;
which means, it ends returning null, so nothing went wrong, hence 200
directly.
Replied to Use Data From Config/app In Javascript File
In i18n.js
, you can use window.App.locale
if you use the example above. In this case, App
is a global variable. Since it is pretty small, you can put it in your layout master file in the HTML header and it would be available in any JavaScript file.
Is it not what you need ?
Replied to Use Data From Config/app In Javascript File
A common practice is to send the data you need in an App
variable :
// In your blade file
<script>
window.App = {!!
json_encode([
'authenticated' => Auth::check(),
'locale' => config('app.locale')
])
!!}
</script>
I added authenticated
to illustrate how you could put other information
Otherwise, maybe you can have your locale
in your html tag
:
<html lang="{{app()->getLocale()}}">
Then use something like this in Javascript:
document.documentElement.lang
Replied to Create Popup Tutorial
For a list of available JavaScript libraries, you can check this: https://github.com/sorrycc/awesome-javascript#tours-and-guides That's the section related to tours and guides.
The awesome lists have a lot of nice package/library suggestions.
Awarded Best Reply on Insert Data Duplicate In Table PeopleDuplicate From ControllerPeople
Here is a correction for your code, I haven't tested it:
public function store(Request $request) {
$people = $request->all();
$duplicate = People::where('name',$people['name'])->where('surname', $people['surname'])->first();
if($duplicate) {
return response()->json(
PeopleDuplicate::create([
'people_id'=> $duplicate->id,
'name'=> $people['name'],
'surname'=> $people['surname']
]), 201);
}
// ...
}
It's just a first step, the code can obviously be optimized but you can notice that:
request()
like this request()->all()
or the variable $request
like this $request->all()
$request->all()
returns an array, $people
is accessed like this $people['name']
Hope this helps
Replied to Insert Data Duplicate In Table PeopleDuplicate From ControllerPeople
Here is a correction for your code, I haven't tested it:
public function store(Request $request) {
$people = $request->all();
$duplicate = People::where('name',$people['name'])->where('surname', $people['surname'])->first();
if($duplicate) {
return response()->json(
PeopleDuplicate::create([
'people_id'=> $duplicate->id,
'name'=> $people['name'],
'surname'=> $people['surname']
]), 201);
}
// ...
}
It's just a first step, the code can obviously be optimized but you can notice that:
request()
like this request()->all()
or the variable $request
like this $request->all()
$request->all()
returns an array, $people
is accessed like this $people['name']
Hope this helps
Replied to Looking For A Recommendation For A No-captcha For Laravel 7
The error Class NoCaptcha not found
is due to the usage of NoCaptcha
in your blade file. The class is not loaded or doesn't exist.
What does your composer.json
look like ?
And more importantly, in your vendor directory, do you have anhskohbo/no-captcha
?
By the way, you can try to run: composer dump-autoload
Replied to Looking For A Recommendation For A No-captcha For Laravel 7
@swimmer you forgot the link :)
By the way, it seems like Google provides some test keys: https://developers.google.com/recaptcha/docs/faq#id-like-to-run-automated-tests-with-recaptcha.-what-should-i-do