vincent15000

vincent15000

Member Since 1 Month Ago

Experience Points
3,370
Total
Experience

1,630 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
1
Lessons
Completed
Best Reply Awards
2
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 1
3,370 XP
Jul
10
13 hours ago
Activity icon

Replied to Ajax With JQuery And Laravel

Well ... the route is behind the auth middleware and I wasn't authenticated.

I am probably very tired ! ;) ...

Activity icon

Replied to Ajax With JQuery And Laravel

Ok thank you. Chrome gives me some additional information.

GET http://localhost:8000/drawings/oeil-de-lynx (Unauthorized)

My routes are ok, GET method is declared in my routes, it works fine without ajax.

Perhaps I have to set an authorization for ajax ?

Activity icon

Replied to How Can I Display Products By Category?

Hello,

First of all, I think that something's wrong in your products table. You should have a field category_id and then set category_id as a foreign key .

$table->unsignedBigInteger('category_id');
$table->foreign('category_id')->references('id')->on('categories')->onDelete('set null');

You Category class has also something wrong.

class Category extends Model
{
    public function childs() {
    	return this->hasMany('App\Products');
    }
}

And you have to add this in your Product model.

class Product extends Model
{
    public function category() {
    	return this->belongsTo('App\Category');
    }
}

I hope this can help you.

Activity icon

Replied to Ajax With JQuery And Laravel

@michaloravec It doesn't work ... I have an error again.

Activity icon

Started a new Conversation Ajax With JQuery And Laravel

Hello,

I have a view with some photos. When I click on one photo, I want to open a modal window with to show some data saved in the database.

I really don't know how to do, I have tried different ways, but there is always an error.

Here is my code.

$.ajax({
    url: 'drawings/'+slug',        // I also tried without slug, same result => error
    type: 'get',
    success: function(data) {
        alert('Succes !!!');
    },
    error: function() {
        alert('Some error occurs !!!');
    },
});
$('#modal_image').content(some_data);
$('#modal_title').content(some_data);

What's wrong in my code ?

Thanks for your help.

Activity icon

Replied to Bootstrap Grid Layout And Cards ...

Ok thank you.

Jul
09
1 day ago
Activity icon

Started a new Conversation Bootstrap Grid Layout And Cards ...

Hello,

I use Bootstrap and I have some difficulty to obtain what I want.

I have 4 cards aligned horizontally with their card-header height depending on the length of the title. I'd like to have the headers height adapt automatically on the height of the heighest header in the same row and then center vertically the title in the card-header.

I don't know if it is possible to do that with Bootstrap.

Thanks for your help.

Jul
08
2 days ago
Activity icon

Replied to Query Result From Two Tables Into One Collection

@ismaile Yooooo ... exactly what I need !!! Thank you !!!

Activity icon

Started a new Conversation Query Result From Two Tables Into One Collection

Hello,

I try to have the result of two queries in one collection.

$creations = Drawing::where('published', 1)->orderBy('creation_date', 'desc')->limit(4)->get();
return view('accueil', compact('creations'));
$creations = Animations::where('published', 1)->orderBy('creation_date', 'desc')->limit(4)->get();
return view('accueil', compact('creations'));

Of course I could have a unique table, but there are very differents fields, so I have two different tables. How can I have both Drawing and Animations in one query ?

Thank you for your help.

Jul
07
3 days ago
Activity icon

Awarded Best Reply on Retrieving All 'id' From A Relationship

I have found the solution.

In my controller, I have to use this code :

$checked_techniques = $drawing->techniques()->wherePivot('drawing_id', $drawing->id)->pluck('id')->toArray();
Activity icon

Replied to Retrieving All 'id' From A Relationship

I have found the solution.

In my controller, I have to use this code :

$checked_techniques = $drawing->techniques()->wherePivot('drawing_id', $drawing->id)->pluck('id')->toArray();
Activity icon

Replied to File(storage/products/dummy/laptop-1.jpg) Is Not Within The Allowed Path(s):

I think that you have the answer in the error message : your storage path is not within the allowed paths. That means that you have defined anywhere in your code some allowed paths.

Activity icon

Started a new Conversation Retrieving All 'id' From A Relationship

Hello,

Impossible for me to find the solution. I have tried very different things, but no result.

I have two three tables : drawings, techniques and drawing_technique. I have defined the relationships (direct and inverse). In the drawing view, the techniques are checkboxes.

  • I save the datas in the relationship table with sync() : no problem.
  • I want to edit the drawing, the checkboxes are not checked as it should be !

Here is my code.

In the controller.

public function edit(Drawing $drawing)
{
    $substrates = Substrate::orderBy('title', 'asc')->pluck('title', 'id');
    $techniques = Technique::orderBy('title', 'asc')->get();
    $categories = Category::orderBy('title', 'asc')->get();
    $checked_techniques = Technique::with('drawings')->find($drawing->id)->toArray();
    return view('drawings.edit', compact('drawing', 'substrates', 'techniques', 'categories', 'checked_techniques'));
}

The view.

<div class="form-group form-check form-check-inline">
    @foreach ($techniques as $technique)
        <div class="form-group custom-control custom-control-inline custom-checkbox">
            {{ Form::checkbox('techniques', $technique->id, in_array($technique->id, $checked_techniques) ? true : false, ['class' => 'custom-control-input', 'id' => 'technique-'.$technique->id, 'name' => 'techniques[]']) }}
            {{ Form::label('technique-'.$technique->id, $technique->title, ['class' => 'custom-control-label']) }}
        </div>
    @endforeach
</div>

If somebody could help me, thank you ;).

Jul
06
4 days ago
Activity icon

Replied to Is Polymorphism The Best Way ?

Ok thank you ;).

Jul
02
1 week ago
Activity icon

Replied to Help With Collection Please - I Am Not Able To Select An Item From The Collection

Hello,

First of all : how many hairs do you still have on your head ? ;) ;) ;)

Well ... sorry ;) ... Something is strange for me : why do you encode and immediately decode JSON ?

I'm interested in your code because I need something similar to save test results for my students : serializing the results for each question and save it into the database.

If you want each user with his notifications, if I look at your code, perhaps you could try this and show the result.

foreach ($users as $user)
{
	dd($user->notifications->notifications);
}
Activity icon

Replied to Testing Password Confirmed Field

Well ... can you show your phpunit code please ?

Activity icon

Replied to Is Polymorphism The Best Way ?

@bobbybouwmann This was effectively my first idea : create one model per activity type. And then each activity type (Video, Audio, Test, Text, ...) have a relationship with the activity model.

That's why I thought about polymorphism. Within a sequence, there are many activities.

sequences : id, title, ...
activites : id, title, comment, activityable_id, activityable_type, order, sequence_id

And for example the Video type.

videos : id, url, ...

Then if I want to create a video activity, I could have :

videos : 14, '/var/www/html/courses/resources/videos/...'
activities : 25, 'Introduction', 'This is the introduction of the course about ...', 14, 'videos', 3, 34

But is this really polymorphism ? I don't know very well polymorphism, only in theory ;).

Activity icon

Awarded Best Reply on Prevent Access To A Model Is User_id != Auth::id()

You can implement a product policy to authorize the access.

Then you can authorize for the action you want : viewall, view, edit, update, delete.

php artisan make:policy ProductPolicy
Jul
01
1 week ago
Activity icon

Replied to How To Retrieve Address Of All User

@golapraj With pleasure. Perhaps you could click for the best answer in order to close this post ?

Activity icon

Replied to Is Polymorphism The Best Way ?

@bobbybouwmann Yes this is useful, your solution seems to be very good. I try it soon.

Now I have one more question. Some activities can be very different, for example a test with some questions and answers. A test has several additional fields that the other activities don't have. I think it is not a good idea to add these specific test fields to the activities table. How can I implement this in the database with only one activities table with different types of activities, and especially some tests ?

In PHP, no problem, I will have a Test model extending my Activity model. The Test model will have the additional fields. So in the database I think that the only solution is to create a specific tests table. I think it is possible, using the same solution you proposed to me, to force another table in the database for my Test table.

Perhaps something like this.

class Test extends Activity
{
    protected $attributes = [
        'type' => 'audio',
	'number_of_trials' => ...
	'delay_after_each_trial' => ...
    ];

    protected $table = 'tests';		// Will this work ?
}

Tonight I don't try anything more, I just post this message before sleeping ;).

Activity icon

Replied to Testing Password Confirmed Field

Hello,

Can you show your form please ?

Activity icon

Replied to Where Are You All From?

Cantal, France

Activity icon

Replied to Prevent Access To A Model Is User_id != Auth::id()

@beertastic Hello is it ok for you ? Does it work fine now ?

Activity icon

Replied to Foreach | Holes In Bootstrap Grid

Sorry but I don't understand where is the hole. In top of your page, I see an ad box.

Activity icon

Replied to How To Retrieve Address Of All User

Good idea @snapey, I didn't know that way.

Activity icon

Replied to How To Retrieve Address Of All User

@golapraj Tell us if it's ok for you please ;).

Activity icon

Replied to How To Retrieve Address Of All User

DB::table('addresses')
	->leftJoin('users', 'users.id', '=', 'addresses.user_id')
	->select('users.name', 'addresses.address')
	->where('addresses.country', 'UK')
	->get();
Activity icon

Replied to How To Retrieve Address Of All User

@golapraj And you can replace join() by leftJoin() or rightJoin() according to your need to discard the users without any address.

Activity icon

Replied to How To Retrieve Address Of All User

@snapey Yes I thought about this solution, but I wonder he wants to retrieve the user name too. Perhaps the solution is with DB::table().

You can try something like this.

DB::table('users)->join('addresses', 'users.id', '=', 'addresses.user_id')->select('user.name', 'addresses.address')->where('addresses.country', 'UK')->get();
Activity icon

Replied to How To Retrieve Address Of All User

Tell me the fields you want to retrive in your collection.

Activity icon

Replied to How To Retrieve Address Of All User

Oh sorry I thought the address was a field of your user table. I just noted that you have a specific table for the addresses.

You have only one address for each user ?

What are the fields in your address table in the database ?

Do you want only the addresses in your collection ?

$addresses = Address::all()->where('country', 'UK')->pluck('address');

Or do you want the addresses with the associated user ?

Activity icon

Replied to How To Retrieve Address Of All User

Hello,

You can try this.

$adresses = User::all()->where('country', 'UK')->pluck('address');

Tell me if it works. ;)

Activity icon

Started a new Conversation Is Polymorphism The Best Way ?

Hello,

I have a personal project to develop a digital-learning platform with some specific features.

Here is my problem. An activity belongs to a sequence, but the activity is of different types : video, text, audio, pdf, test, ...

To link the different activity types to the activity model, do I have to use polymorphism ? => activities with activityable_id and activityable_type to link with the different activities ?

In PHP that's heritage : video extends activity / test extends activity / ...

But how is it possible to implement this with Eloquent ?

Thanks for your help.

Vincent

Jun
30
1 week ago
Activity icon

Replied to Foreach | Holes In Bootstrap Grid

Hello,

That's difficult to answer.

Do you have a screenshot ?

Activity icon

Replied to Prevent Access To A Model Is User_id != Auth::id()

Ok that's if it works.

Perhaps you could notice the best answer ?

Thanks.

Activity icon

Replied to Pivot Table Update: UpdateExistingPivot Or SyncWithoutDetaching? Neither Works

No problem.

Me too I didn't care at all about the the first parameter.

Simple solution are sometimes the more difficult to find because we don't look at the good part of code.

Good luck.

Activity icon

Replied to Pivot Table Update: UpdateExistingPivot Or SyncWithoutDetaching? Neither Works

$line = CartProduct::firstOrCreate([
      'product_id' => $product->id,
      'cart_id' => $cart->id,
      'size' => $size ? $size : '',
      'color' => $color ? $color : '',
    ]);

The documentation shows that when you are using a firstOrCreate() method, save() is not useful. firstOrCreate() creates and saves the datas. So perhaps you create a first time with firstOrCreate() and a second time with updateExistingPivot().

Your problem of duplication is perhaps with your firstOrCreate() method. Perhaps you can try to comment the updateExistingPivot() line to check wether a new line is created or not.

Activity icon

Replied to Pivot Table Update: UpdateExistingPivot Or SyncWithoutDetaching? Neither Works

There's a problem ... with another product, you have the same product_id ... that's not normal.

Activity icon

Replied to How To Point The To The Value Of A Foreign Key And Not The Id

I have updated the post with leavetype() instead of leave_type(). ;)

Activity icon

Replied to Pivot Table Update: UpdateExistingPivot Or SyncWithoutDetaching? Neither Works

And can you add a product in your cart, show the dd($line) (or your other function), then add another product in the same cart, and show the dd($line) once again ?

Activity icon

Replied to Prevent Access To A Model Is User_id != Auth::id()

You can implement a product policy to authorize the access.

Then you can authorize for the action you want : viewall, view, edit, update, delete.

php artisan make:policy ProductPolicy
Activity icon

Replied to Pivot Table Update: UpdateExistingPivot Or SyncWithoutDetaching? Neither Works

That's strange that you have the same behavior after deleting the save() or update() method.

Can you write a dd($line) after your $line = ... and give me the result ?

$line = CartProduct::firstOrCreate([
      'product_id' => $product->id,
      'cart_id' => $cart->id,
      'size' => $size ? $size : '',
      'color' => $color ? $color : '',
    ]);
dd($line);
Activity icon

Awarded Best Reply on How To Point The To The Value Of A Foreign Key And Not The Id

Hello,

I am not sure, perhaps this could work.

if ($leaverequest->leavetype()->leave_type_name == 'Annual' || $leaverequest->leavetype()->leave_type_name == 'Annual Leave')
{
	...
}
else
{
	...
}

Tell me if it is ok.

Activity icon

Replied to How To Point The To The Value Of A Foreign Key And Not The Id

Oh sorry it is leavetype() and not leave_type.

I mean the function you implemented in your model.

Activity icon

Replied to Pivot Table Update: UpdateExistingPivot Or SyncWithoutDetaching? Neither Works

I had a look at the documentation.

I think that it is not necessary to user the save() method.

Only updateExistingPivot() or syncWithoutDetaching() method.

The save or update action seems to be implicit when using updateExistingPivot() or syncWithoutDetaching().

So I wonder your save() method adds a new row, but the existing ones which you want to update with updateExistingPivot() are already updated.

Activity icon

Replied to Re-use Form Component For Edit And Create

@rhys ok ... sorry I can't help you with vue.js

Activity icon

Replied to Localization With The Database

Oh thank you I didn't know it. That's exactly what I need.

Activity icon

Started a new Conversation Localization With The Database

Hello,

I have no problem with a standard localization with the fr, en, ... folders. What I need to do is to be able to save some new rows in my tables in different languages.

Example with a categories table. If I want to translate my website in different languages, each time I add a new category, I have to translate it. How to do that ? I thought about different language fields in the database, but what's up if I want to add another language ?

id english name french name spanish name ...

I don't think that's the good idea.

Thanks for your help.

Vincent

Jun
29
1 week ago
Activity icon

Replied to Pivot Table Update: UpdateExistingPivot Or SyncWithoutDetaching? Neither Works

Hello,

I am not sure ...

Would it be the save() method which is reponsible of the addition of a new row ?

Perhaps you should use the update() method instead ?

Tell me if I'm wrong please.