manelgavalda

manelgavalda

FullStack Developer at Self Employed

Member Since 2 Years Ago

Roquetes

Experience Points
206,740
Total
Experience

3,260 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
1284
Lessons
Completed
Best Reply Awards
124
Best Reply
Awards
  • start-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-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-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist 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 42
206,740 XP
Feb
15
1 week 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
2 weeks 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
2 weeks 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 weeks 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 weeks 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 weeks 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 weeks 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 weeks 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
1 month 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
1 month 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.

Activity icon

Replied to Saving Additional Data On A Pivot Table (Multiple Entries)

I don't understand what you are trying to do, if you need to store an arrayinto a integer field, it would not work.

If you want to save an array into the database you can use a string field, and then making use of data casting so you can retrieve it as an array easly.

When you are doing this:

$dispatch->sub_jobs()->attach($sub_job_ids, ['qty' => $sub_job_qtys, 'description' => $sub_job_descriptions]);

What do you expect to save, 1 row, or many rows depending on the length of the array?

Activity icon

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

Show us your store controller method, and your view to see how are you calling it.

Activity icon

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

This problem is saying that your controller expects 1 parameter and you are not passing it, so your route definition and controller are good. If you are doing something like this:

<a href="{{route('documentmodal_store',$list->pg_id)}}"></a>

Make sure that $list->pg_id is not null.

Activity icon

Replied to Saving Additional Data On A Pivot Table (Multiple Entries)

When you do this:

$sub_job_qtys = $job->sub_jobs->pluck('qty');

You are getting an array with the plucked values, so you are trying to insert an array on an integer field. What are you trying to do?

Activity icon

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

The resource routes will automatically create the route pattern with the variables in place, so you don't need to add the $id in the route:

Route::resource('pg/document', 'pages\DocumentController')
->names(['store'=>'documentmodal_store','destroy'=>'document_delete']);
Activity icon

Replied to Htmlspecialchars() Expects Parameter 1 To Be String, Object Given

$bookings is a collection, so you need to encode it to json in order to pass it to your Vue component:

<booking :bookings="{{ json_encode($bookings) }}"></booking>
Jan
15
1 month ago
Activity icon

Replied to Import Bugs

Show us some code please.

Jan
13
1 month ago
Activity icon

Replied to Slightly Different Versions Of PHP And Laravel.

The laravel versions depends on the project, so if you are working on the same project in your house and office the version won't change, the only problem will be the PHP version. If you are actually working with the laravel 6.2 you will have problems when you try to work with the same project at home, but if you work with the 5.8 version, you can work in both places without a problem.

Activity icon

Replied to View Composer

Hey, $accounts its a collection so you need to first pull one account to get the property. What are you trying to do?

Jan
11
1 month ago
Activity icon

Awarded Best Reply on Show Name Roles In A View Blade With Bouncer

You can chose between the implode or the foreach, not both at the same time:

  • If you want to show all the roles separated by commas you can use this:
    {{ $user->getRoles()->implode(', ')  }}

This will actually convert your collection ([ "RoleName1", "RoleName2" ]) to a string separated by commas (RoleName1, RoleName2).

  • The other option is to use the foreach, so you will list each individual role:
@foreach($users as $user)

    {{ $user->name }}

    @foreach($user->getRoles() as $roleName) // If you use this method remove the `implode`
          {{ $roleName}}
    @endforeach

@endforeach
Jan
10
1 month ago
Activity icon

Replied to Show Name Roles In A View Blade With Bouncer

Cool, glad it worked! Please mark it as solved, so other people will know.