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.
Awarded Best Reply on Search In Table Related To Eloquent
@datanorte You can use whereHas()
in that case. I assume that brand
table has name
field and category
has title
filed those you want to search.
public function render()
{
$data_products = Product::with('brand', 'category')->orderBy('id', 'desc')
->where('name', 'like', '%' . $this->search . '%')
->orWhereHas('brand', function($query) use($search = $this->search){
$query->where('name', '%' . $search . '%')
})->orWhereHas('category', function($query) use($search = $this->search){
$query->where('title', '%' . $search . '%')
})->paginate($this->perPage);
return view('livewire.products', compact('data_products'));
}
Note: You need to adjust the query based on your requirements.
Ref: https://laravel.com/docs/8.x/eloquent-relationships#querying-relationship-existence
Awarded Best Reply on IsoFormat Error In Laravel
@amit028 Is that somehow a composer installation issue?
Can you try this?
composer clearcache
composer install
Replied to Composer Error When I Try To Use Composer Commands
@deekshith It's a php / laravel package.
Allow you to display update/upgrade instructions to your library users.
Replied to Composer Error When I Try To Use Composer Commands
@deekshith This means, your php version is 7.1.33 but for some reasons (probably some of the packages need a higher version of php) composer required 7.2.5 version or above.
So, if possible, I strongly suggest you to upgrade php version at least. It's recommeneded also to upgradate Laravel version (The current version is 8 and you are using 5.5)
Replied to Composer Error When I Try To Use Composer Commands
@deekshith Try-
I have had to delete the directory
kylekatarnls
located inside myvendor
directory then runcomposer update --prefer-source
and after thatcomposer dump-autoload
.
Replied to Take Specific Column From Multi-dimensional Arra
@tapas Doesn't it simpler approach?
Model::get('company_name', 'position');
Replied to Connection With Multiple Database In Lumen
Replied to Display Products Of Each Category In Laravel
@mehrdad70 Try this-
public function showCourses()
{
$courses = Course::with('categories')->get()
retuern view('front.courses.all-courses', compact('courses'));
}
@foreach($courses as $course)
// To print anything from category table
{{ $course->categories->fieldName }}
@endforeeach
Here you need to adjust the fieldName
based on your table column.
SideNote: I highly recommend you to check this doc and watch some basic laravel series that will boost up your skills.
Replied to How To Save Two Different Data In One Column.
@emfinanga It's because of you are assigning slave_id
into unit_id
. Look at your following code that is wrong-
$data = New Mystock;
$data->unit_id = $value->unit_issue_id;
$data->unit_id = $value->slave_id;
It should be like this-
$data = New Mystock;
$data->unit_id = $value->unit_issue_id;
$data->slave_id = $value->slave_id;
...
You just adjust your $data->slave_id
if the table column is wrong.
Replied to Develop RSS News Feed With Laravel And RSS Tracker In Localhost?.
@munazzil It's a big old tho, but you can follow that.
https://www.itsolutionstuff.com/post/task-scheduling-with-cron-job-in-laravel-58example.html
Replied to Best🪡Way
@konstruktionsplan First of all, your query has an issue mentioned by @prasadchinwal5 . Check it out.
Secondly, if you are looking for the best way, then I would recommend you to use eloquent for that. Since you are able to join tables via the foreign key, you can easily build a relationship between them. Then you can create a dedicated method to grab the point.
Replied to File Upload Refactoring
@uniqueginun The approach suggested by @tray2 looks clean enough already.
Why not you just create separate methods and handle all the logic insider them.
BTW, you can use a loop if you want, but since you can solve any issue without the loop, then what is the purpose of using it? Looping will make iteration, which may affect your performance (depends on how many times it iterate). Therefore I believe looping is unnecessary use here.
Replied to Develop RSS News Feed With Laravel And RSS Tracker In Localhost?.
@munazzil If I understand you correctly, you want to fetch real-time.
In that situation, you need to use any JS library / Cron Job for pulling data at certain intervals. Or you need to use any third-party library to solve the issue.
Replied to File Upload Refactoring
@uniqueginun First of all, if your current code works fine, I would say just follow the simple step, that currently has.
Secondly, if you submit multiple form on same action and not sure whether in future it will submit more form or not, on that situation, you can follow a separate class for each form submittion based on a contract (Interface), that will be following Open Closed Principle (Some may be refer it over engineering of it here).
That's what I can think of now.
Awarded Best Reply on Accessing Parent Method From Subclass Instantiation
@zaimazhar You just add return $this;
in your awarded()
method. That should work.
public function awarded($user) {
$this->user = $user;
return $this;
}
Replied to Accessing Parent Method From Subclass Instantiation
@zaimazhar You just add return $this;
in your awarded()
method. That should work.
public function awarded($user) {
$this->user = $user;
return $this;
}
Replied to File Upload Refactoring
@uniqueginun Why do you need refactoring here? I cannot see any complexity here.
Replied to IsoFormat Error In Laravel
@amit028 Is that somehow a composer installation issue?
Can you try this?
composer clearcache
composer install
Awarded Best Reply on How Can I Give Multiple Condition In @can Laravel
@niush If I understand correctly, @canany()
will check whether the user is eligible for any of the gate of the given array. Correct me if I am wrong.
@nafeeur10 I found the following in the discussion, but not in the official documentation. You can try it if it works.
@if(Gate::check('user_manage') && Gate::check('client_manage'))
@endif
Ref: https://stackoverflow.com/questions/34188461/laravel-5-1-can-how-use-or-clause
Replied to How Can I Give Multiple Condition In @can Laravel
@niush If I understand correctly, @canany()
will check whether the user is eligible for any of the gate of the given array. Correct me if I am wrong.
@nafeeur10 I found the following in the discussion, but not in the official documentation. You can try it if it works.
@if(Gate::check('user_manage') && Gate::check('client_manage'))
@endif
Ref: https://stackoverflow.com/questions/34188461/laravel-5-1-can-how-use-or-clause
Replied to BelongsToMany Take 1 .
@binggle Actually you are right if you try many to many relationships.
In that case, the access way would be a bit different.
$category = Cat::find(1);
foreach ($category->videos as $video) {
//
}
Ref: https://laravel.com/docs/8.x/eloquent-relationships#many-to-many-model-structure
Replied to Trying To Get Property 'courses' Of Non-object
@mehrdad70 Can you dd($cart)
and show the output of it?
Replied to Call To Undefined Method Illuminate\Database\Eloquent\Relations\MorphMany::attach()
@neeraj1005 Just to confirm, isn't that unnecessary to pass user id to validation data since you are using attach()
? It should take user_id
automatically. Correct me if I am wrong.
Replied to BelongsToMany Take 1 .
@binggle I think you provided belongsToMany()
in both sides. Therefore, you are getting only one result.
So, you need to change your relationship a bit.
On cat.php model-
public function videos()
{
return $this->hasMany( Video::class, 'cat_video' )->withTimestamps();
}
Now it should work.
Ref: https://laravel.com/docs/8.x/eloquent-relationships#one-to-many
Replied to Trying To Get Property 'courses' Of Non-object
@mehrdad70 Just wrap by if
condition. It will ensure that the $cart
return values.
$cart = Auth::user()->carts()->where('status', Cart::Active)->first();
//The reason for this error is
if($cart){
if(!is_null($cart->courses)){
$courses = $cart->courses;
return view('front.shoping-cart.cart', compact('courses', 'cart'));
}else{
$cart->delete();
return view('front.shoping-cart.empty-cart');
}
}
Replied to Laravel Pagination Multilang
@caglayantolga35 I never worked for pagination. But I guess this link might be helpful for you.
Replied to How Can I Save Request Data Into Database At Once?
@cola Yes, it should be like that, I believe.
Awarded Best Reply on Parse Error I Need Answer
@cüneyd alper dereli In the constructor, you need to give space after function
keyword. Currently, there is no space.
It should be-
public function __construct($pdo){
$this->pdo = $pdo;
}
Replied to Parse Error I Need Answer
@cüneyd alper dereli In the constructor, you need to give space after function
keyword. Currently, there is no space.
It should be-
public function __construct($pdo){
$this->pdo = $pdo;
}
Replied to How Can I Save Request Data Into Database At Once?
@cola You can. But you need to change a few things-
User::create($request->only(['firstName', 'lastname', 'email', 'password']));
Now in your model, make sure that you allow mass assignment.
User.php
protected $guarded = [];
// This for password bcrypt.
public function setPasswordAttribute($value){
$this->password = bcrypt($value);
}
Replied to Parse Error I Need Answer
@cüneyd alper dereli Show your code. You have made a mistake in your code probably.
Awarded Best Reply on Optional Inclution Of Template
@afoysal May be you can create an another @yield
then use that new yield for inserting header
and sidebar
template.
For example-
<body>
<div id="main-wrapper">
@yield('extra-layout')
<div class="content-body">
<div class="container">
@yield('content')
</div>
</div>
</div>
@include('modal')
@include('layouts.footer-script')
</body>
Now, wherever you need, in the extended template would be-
@section('extra-layout')
@include('layouts.header')
@include('layouts.sidebar')
@stop
Replied to Undefined Variable Exception When Queuing Notifications
@elo Does log file show more details? Have you used any variable $totalSponsorshipAmt
in the blade file?
@neeraj1005 Yes, but once you submit the form, normally checkbox returns on
or off
based on whether you checked or not.
Since you directly create the value into the table, Rfq::create($validatedData);
therefore it takes checkbox value as on
. That's why I suggest whether you change the value as an attribute or change the table value to a string.
Replied to Optional Inclution Of Template
@afoysal May be you can create an another @yield
then use that new yield for inserting header
and sidebar
template.
For example-
<body>
<div id="main-wrapper">
@yield('extra-layout')
<div class="content-body">
<div class="container">
@yield('content')
</div>
</div>
</div>
@include('modal')
@include('layouts.footer-script')
</body>
Now, wherever you need, in the extended template would be-
@section('extra-layout')
@include('layouts.header')
@include('layouts.sidebar')
@stop
@neeraj1005 It's because you set column type as an integer and providing some text (by default check box return on or off).
Probably you can set mutator here
public function setIsCheckedAttribute($value)
{
$this->attributes['isChecked'] = (bool) $value;
}
Or on the migration file, just set the integer to string. Like that-
$table->string('isChecked');
Ref: https://stackoverflow.com/questions/42166853/store-true-as-1-false-as-0-using-laravel-eloquent-mysql
Replied to Looking To Hire A PHP/Laravel Developer
@mkellyxp This may not the right place to post. However, if you want, you can post your job at https://larajobs.com/
Replied to Can't See Error
@nikhillvl Make sure, you have .env
file in the project.
And if it's in local environment, turn APP_DEBUG=true
value into true
.
Awarded Best Reply on Showing User Posts
@pt-83 The view should be like this-
@foreach ($posts as $post)
<div class="blogs bg-white mr-5">
<img src="{{ $post->file }}" class="">
<div class="p-5">
<h1 class="text-2xl font-bold text-green-800 py-2">{{ $post->title }}</h1>
<p class="bg-white text-sm text-black">{{ $post->body }}</p>
<a href="{{ route('posts.show', $post) }}" class="py-2 mt-4 px-6 text-white bg-green-500 inline-block rounded">Read More</a>
</div>
</div>
@endforeach
Replied to Showing User Posts
@pt-83 The view should be like this-
@foreach ($posts as $post)
<div class="blogs bg-white mr-5">
<img src="{{ $post->file }}" class="">
<div class="p-5">
<h1 class="text-2xl font-bold text-green-800 py-2">{{ $post->title }}</h1>
<p class="bg-white text-sm text-black">{{ $post->body }}</p>
<a href="{{ route('posts.show', $post) }}" class="py-2 mt-4 px-6 text-white bg-green-500 inline-block rounded">Read More</a>
</div>
</div>
@endforeach
Replied to Lesson 3 TDD: Differences Between Create, Make, Raw
If you have extended a model, you may wish to extend its factory as well in order to utilize the child model's factory attributes during testing and seeding. To accomplish this, you may call the factory builder's raw method to obtain the raw array of attributes from any given factory:
For example-
$factory->define(App\Admin::class, function (Faker\Generator $faker) {
return factory(App\User::class)->raw([
// ...
]);
});
Replied to Lesson 3 TDD: Differences Between Create, Make, Raw
@gianmarx The create
persists to the database while make
just creates a new instance of the model.
The create
method not only creates the model instances but also saves them to the database using Eloquent's save method
https://laravel.com/docs/8.x/database-testing#creating-models-using-factories
Awarded Best Reply on Target Class...does Not Exist Error Only On Production, Not Dev
@aylara I guess it's the issue of case sensativity. Since it's working fine locally with the code, and if you push your code properly into the server, then change this code. Locally it may not affect but on the server, Api
is not the same as api
.
It should be
Route::apiResource('enquiries','Api\WebsiteEnquiryController');
Instead of -
Route::apiResource('enquiries','api\WebsiteEnquiryController');
Replied to HasOne Relationship With Condition
@uniqueginun well, in that case, you are trying to match with a specific date. Now question is, how do you store data in your DB? What is formate?
BTW, are you getting anything with substitutionEmployee()
?
Replied to HasOne Relationship With Condition
@uniqueginun It should work. Actually, it will get the associate start_date
from the model.
Earned once your experience points ranks in the top 10 of all Laracasts users.