manelgavalda

manelgavalda

FullStack Developer at Self Employed

Member Since 2 Years Ago

Roquetes

Experience Points
214,310
Total
Experience

690 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
1330
Lessons
Completed
Best Reply Awards
128
Best Reply
Awards
  • start your engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-in-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist Created with Sketch.

    Laracasts Evangelist

    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.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 43
214,310 XP
May
21
3 days ago
Activity icon

Awarded Best Reply on (2/2) ErrorException Invalid Argument Supplied For Foreach() (View: C:\laragon\www\path\resources\views\pages\knowledgebasecategory.blade.php)

Looks like your $knowledgebasecategory->knowledgebases relation is not working (probably returning null or 1 record). Do you have the knowledgebases relation correctly defined in your KnowledgebaseCategory model to return a collection?

// app/KnowledgebaseCategory.php
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class KnowledgebaseCategory extends Model
{
...
    public function knowledgebases()
    {
        return $this->hasMany(KnowledgeBase::class);
    }
...
}
May
09
2 weeks ago
Activity icon

Awarded Best Reply on How To Resolve: "Trying To Get Property 'email' Of Non-object"

first() returns you the first result of the query you made, if there are no results it returns null. So you are trying to get the email from null. Check that the record you are searching exists in the database.

Apr
23
1 month ago
Activity icon

Replied to How To Resolve: "Trying To Get Property 'email' Of Non-object"

first() returns you the first result of the query you made, if there are no results it returns null. So you are trying to get the email from null. Check that the record you are searching exists in the database.

Activity icon

Replied to How To Resolve: "Trying To Get Property 'email' Of Non-object"

Hey, are you sure that the query without first() is returning you anything?

Apr
21
1 month ago
Activity icon

Replied to Cannot Run Php Artisan Migrate Commands. Error: SQLSTATE[HY000] [1049]

You need to login into your mysql and create your database first:

CREATE DATABASE testproject2;
Mar
19
2 months ago
Activity icon

Replied to Laravel CSRF - 419 Page Expired With Post Request To Other Website

Hey, If you have 2 websites, and your website A want to make a petition to website B, you need to disable the CSRF token verification from the uri you are trying to access.

Go to your VerifyCsrfToken on your website B and disable the CSRF verification for the uri that the website A is trying to access, with the $except property:

class VerifyCsrfToken extends Middleware
{
    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [
        'your-uri'
    ];
}

Docs: https://laravel.com/docs/master/csrf#csrf-excluding-uris

Mar
17
2 months ago
Activity icon

Awarded Best Reply on Laravel Mail By Markdown Messages

I think the variable should be a public property on the Mail class to access it on the view:

...
class CommentSendMail extends Mailable
{
    use Queueable, SerializesModels;

    public $user; 
...
Activity icon

Replied to Laravel Mail By Markdown Messages

I think the variable should be a public property on the Mail class to access it on the view:

...
class CommentSendMail extends Mailable
{
    use Queueable, SerializesModels;

    public $user; 
...
Mar
04
2 months ago
Activity icon

Replied to How To Count Duplicate Relationships With Laravel Eloquent

I don't know if this is what you are looking for, but you can use the withCount method on your lamps relation, to get the number of lamps:

$order->withCount('lamps');

https://laravel.com/docs/7.x/eloquent-relationships#counting-related-models

Feb
24
3 months ago
Activity icon

Awarded Best Reply on How To Dynamically Set Active Link Class

Use double quotes instead:

@foreach ($array_categories as $category)
<li class="nav-item "><a class="nav-link {{ request()->is("category/{$category->slug}") ? 'active' : ''}}" href="/category/{{$category->slug}}">{{$category->name}}</a></li>
@endforeach
Activity icon

Replied to How To Dynamically Set Active Link Class

Use double quotes instead:

@foreach ($array_categories as $category)
<li class="nav-item "><a class="nav-link {{ request()->is("category/{$category->slug}") ? 'active' : ''}}" href="/category/{{$category->slug}}">{{$category->name}}</a></li>
@endforeach
Feb
15
3 months ago
Activity icon

Replied to DB Where And - Is It Possible?

Just use where 2 times:

DB::table($this->tablex)->where('user_id', '=', Auth::user()->id)->where('product_id', '=', $slug)->delete();
Feb
04
3 months ago
Activity icon

Awarded Best Reply on Help

In case you are overwriting a method, in your LoginController make sure that you are using the correct Request class,. On the top:

use Illuminate\Http\Request;
Activity icon

Replied to Help

In case you are overwriting a method, in your LoginController make sure that you are using the correct Request class,. On the top:

use Illuminate\Http\Request;
Feb
03
3 months ago
Activity icon

Replied to Laravel Serialize Response

Which problem do you have?

Activity icon

Replied to Remove Vue On Auth Installation

I don't think there's a command to actually remove it.

What you can actually do is to use git to track the changes that php artisan ui vue --auth does. So next time commit the changes before running the artisan ui command, and you will exactly know the changes.

So as for a solution to your problem you can actually create a new laravel project and commit the changes before running the artisan ui comand, this way you can see all the changes and remove them in your main project.

Activity icon

Replied to Laravel Serialize Response

What problem do you have when doing it?

return response()->json([
    'error'=>false,
    'offers'=> serialize($newData)
]);
Jan
30
3 months ago
Activity icon

Replied to How To Stop Seeing Error Code In Laravel

I don't know the error you are getting, but If you are getting a 500 error what do you want to see instead?

Jan
28
3 months ago
Activity icon

Replied to Lara Nova

Hey, to make things easy I suggest you to just try with the first field, if it works we will add the last.

  • First make sure that the name field is casted to json with the casts attribute in your normal model.

  • Then do this directly in your nova Model:

Text::make('Name', function () {
    return optional($this->resource->name)->first;
})

This just works, if it doesnt, paste the code of your nova model, your migration and your normal model to see what's wrong.

Activity icon

Awarded Best Reply on Creating Migrations From Existing Database

I recommend you to use just a package. There's plenty of packages that do this, for example this one: https://github.com/Xethron/migrations-generator

If you need laravel 6 compatibility: https://github.com/oscarafdev/migrations-generator

Activity icon

Replied to Creating Migrations From Existing Database

I recommend you to use just a package. There's plenty of packages that do this, for example this one: https://github.com/Xethron/migrations-generator

If you need laravel 6 compatibility: https://github.com/oscarafdev/migrations-generator

Activity icon

Awarded Best Reply on How To Find Expired Records Of 1 Month With Eloquent?

You can use a normal where with carbon. I think something like this should do the job:

Order::with('users')
        ->where('created_at', '<=', now()->subMonth())
        ->get()

Edit: As @snapey pointed out you don't need the ->toDateTimeString() on the carbon instance.

Activity icon

Replied to How To Find Expired Records Of 1 Month With Eloquent?

I don't know if I understand it properly, but when you say that you want the records that the created_at + 1 month is less (older) than the date of today,

it's not the same thing as saying the records which the created_at is at least 1 month older than now?

Activity icon

Replied to How To Find Expired Records Of 1 Month With Eloquent?

You can use a normal where with carbon. I think something like this should do the job:

Order::with('users')
        ->where('created_at', '<=', now()->subMonth())
        ->get()

Edit: As @snapey pointed out you don't need the ->toDateTimeString() on the carbon instance.

Activity icon

Awarded Best Reply on How To Use Multiple Database Connection In Laravel (mysql And Oracle)

There's a closed github issue about this on the package, so it will probably be worth it to take a look as there are many solutions: https://github.com/yajra/laravel-oci8/issues/506

Jan
27
3 months ago
Activity icon

Replied to Lara Nova

If you are getting this error is probably because one of your db record doesnt have a correct name field.

If it's a collection you can use the optional operator for example, to avoid the error:

    return optional($this->name)->first . ' ' . optional($this->name)->last;
Activity icon

Replied to Lara Nova

Is your json field correctly casted? Something like, in your model:

protected $casts = [
     "name" => "array"
];

Then access it like an array (using my way or @musa11971 way):

    return $this->name['first'] . ' ' . $this->name['last'];

If you are still getting this error make sure that the json field is not null or not correctly formatted.

Activity icon

Replied to Lara Nova

I suggest you to use a custom accessor.

Firstly add this in your app model:

getFullNameAttribute() {
    return $this->name->first . ' ' . $this->name->last;
}

Then in your laravel nova model access it like this:

Text::make('FullName', 'full_name')
    ->exceptOnForms(),
Jan
24
4 months ago
Activity icon

Awarded Best Reply on Elequent Model Setup Issue

That's the problem, that companyId is an array. Then it retrieves a collection with 2 items. So you need to do ->section() on a item in the collection not in the collection itself.

For example if you want to get the section from the first item use first():

echo($this->find($companyId)->first()->section);
Activity icon

Replied to Elequent Model Setup Issue

That's the problem, that companyId is an array. Then it retrieves a collection with 2 items. So you need to do ->section() on a item in the collection not in the collection itself.

For example if you want to get the section from the first item use first():

echo($this->find($companyId)->first()->section);
Activity icon

Replied to Elequent Model Setup Issue

Your relationship seems correct. What is the value of $companyId? If you are not passing an integer to find it will return a collection, so companyIdis not a company id.

$this->find($companyId) is returning you a collection not a single Company instance:

echo($this->find($companyId)->first()->section()->get());

Show the result of dd($companyId) to see what it is

Jan
23
4 months ago
Activity icon

Commented on One-to-Many

He defines the foreign key using Sequel Pro before going to laravel but the normal thing will be to define it in the laravel migration.

Activity icon

Replied to Dynamic Fillable

First of all add the field relation on your people model:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class People extends Model
{
    protected $fillable = [
        'name', 'address', 'phone', 'email'
    ];

    public function fields()
    {
        return $this->hasMany(Field::class);
    }
}

Create a Field model (and the migration) with your field title, your type, value of the field, and person_id :

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Field extends Model
{
    protected $fillable = [
        'name', 'type', 'value', 'person_id'
    ];
}

Then when you are going to save the values, you can do this:

        $fields = [
            new Field(['name' => 'field_1', 'type' => 'string']),
            new Field(['name' => 'field_2', 'type' => 'text']),
            new Field(['name' => 'field_3', 'type' => 'integer']),
            new Field(['name' => 'field_4', 'type' => 'longText']
        ];

        $person->fields()->saveMany($fields);

Then you can update the values or acces them via the relationship

$person->fields()->where('name', 'field_1')->update('value', 'yourvalue');
$person->fields->firstWhere('name', 'field_1') // yourvalue
Activity icon

Replied to MessageBag In Form Request

You can add an erorr bag property on your request classes.

 protected $errorBag = 'firstForm';
Activity icon

Replied to Dynamic Fillable

Because what you are trying to do it's not possible.

If you want dynamic fields for your model you need to have one table with the model, another with the fields and a relation between them, so each model can have many fields, and you can create them on the fly.

$model -> hasMany -> fields

That's 2 tables minimum, then the fields table will be something like this:

  • title
  • value

so in your model you can acces the fields relation to see your dynamic fields value.

$model->fields->yourDynamicField

Then you can use the excel or whatever you want to create the dynamic fields.

Activity icon

Replied to MessageBag In Form Request

From docs https://laravel.com/docs/5.8/validation#named-error-bags :

return redirect('register')
            ->withErrors($validator, 'login');
{{ $errors->login->first('email') }}
Activity icon

Replied to Dynamic Fillable

What do you mean by dynamic fields? If you want to set all table fields as fillable without adding it to the fillable attribute, you can use the guarded attribute instead:

protected $guarded = [];
Activity icon

Replied to How To Use Multiple Database Connection In Laravel (mysql And Oracle)

There's a closed github issue about this on the package, so it will probably be worth it to take a look as there are many solutions: https://github.com/yajra/laravel-oci8/issues/506

Activity icon

Commented on The Example MySQL Database

Same error using phpmyadmin. In my case I used the terminal:

mysql -u root -proot tutorial < sakila-db/sakila-schema.sql

Then do the same when importing the data, but change the use sakila database statement in the beginning of the file first, and then import the data:

mysql -u root -proot tutorial < sakila-db/sakila-data.sql
Jan
21
4 months ago
Activity icon

Replied to Partials Select Dropdown

If nobody changed the default views path, it should be the file resources/views/partials/input.blade.php

Activity icon

Replied to How To Update The Last_login Value When User Submitted Form?

If you want to update the last_login value just if it doesnt have one, you can do something like this:

protected function authenticated(Request $request, $user)
{
        if (is_null($user->last_login_at)) {
            $user->update(['last_login_at' => now()]);

            return redirect('admin/customers/create');
            // and laravel will then handle the redirect
        }
}
Activity icon

Replied to Unique Row Count Based On The Group By Conditaion

You can do it like this, for example:

DB::table('visitor_count')->get()->groupBy('user_ip')->count()
Activity icon

Replied to Partials Select Dropdown

If you don't want the user to select options of the dropdown, you can use the disabled attribute. Open your partials.input partial to see the best way to implement it.

Activity icon

Replied to Add Click Event Inside Sweet Alert

Can you show the whole Vue component and see how you added the sweet alert modal.

Activity icon

Replied to Add Click Event Inside Sweet Alert

Mm, I tried the example above and it should work. The checkboxValue should be null because it's initialized to null, but the checkboxChecked property should return a boolean if the chekbox is checked or not, so I'm not quite sure what the problem is.

You can take a look at the docs also: https://fr.vuejs.org/v2/guide/forms.html#Checkbox

Activity icon

Replied to Add Click Event Inside Sweet Alert

What problem are you having?

Activity icon

Replied to Add Click Event Inside Sweet Alert

One way would be to add a v-model attribute and then use a watcher on it if you want to do something when the value changes:

...
<input type="checkbox" class="form-check-input" id="exampleCheck1" :value="checkboxValue" v-model="checkboxChecked"> </td>
...
data: () => ({
    checkboxValue: null,
    checkboxChecked: null
})
...
watch: {
    checkboxChecked(checkboxChecked) 
    {
        console.log(checkboxChecked)
        console.log(this.checkboxValue)
    }
},
Jan
20
4 months ago
Activity icon

Replied to Route Pattern "/pg/profile/{id}/{{id}}" Cannot Reference Variable Name "id" More Than Once.

I want to see the storemethod for your ProfileController, and also the html where you are calling the documentmodal_store route.

Activity icon

Replied to Route Pattern "/pg/profile/{id}/{{id}}" Cannot Reference Variable Name "id" More Than Once.

You are showing the destroy method not the store method. And also show you blade to see how are you calling this route.