Heimdall

Heimdall

Member Since 5 Months Ago

Experience Points
2,540
Total
Experience

2,460 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
0
Lessons
Completed
Best Reply Awards
0
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
2,540 XP
Mar
29
1 week ago
Activity icon

Replied to Only One Display On Relation With Pivot Table

@sti3bas Oh yesss, thank you so much :)))

but i have a last little question : For display on my vue, when i foreach like this :

    @foreach($dish_by_category -> dishes as $dishs)

      {{$dishs->name}}

      @endforeach

i have this error :

Property [dishes] does not exist on this collection instance. (View: C:\laragon\www\restaurant\resources\views\category\index.blade.php) 
Activity icon

Started a new Conversation Only One Display On Relation With Pivot Table

Hello

I have problem and i don't know how resolve it ...

I have 3 table : dish / category and pivot table

Each dish can belong to several categories and each category can have several dishes

My pivot table:

public function up()
{
    Schema::create('category_dishes', function (Blueprint $table) {
        $table->id();
        $table->integer("categories_id");
        $table->integer("dishs_id");
        $table->timestamps();
    });
}

My dish table :

    public function up()
    {
        Schema::create('dishs', function (Blueprint $table) {
            $table->id();
            $table->string("name");
            $table->string("price");
            $table->string("description");
            $table->string("image");
            $table->timestamps();
        });
    }

My table category:

    public function up()
    {
        Schema::create('categories', function (Blueprint $table) {
            $table->id();
            $table->string("name");
            $table->string("icon");
            $table->timestamps();
        });
    }

My model :

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Category extends Model
{
    protected $table = 'categories';

        public function Dishes()
    {
        return $this->belongsToMany('App\Dishs', 'category_dishes', 'dishs_id', 'categories_id');
    }
}

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Dishs extends Model
{
    protected $table = 'dishs';

    public function Category()
    {
        return $this->belongsToMany('App\Category', 'category_dishes', 'categories_id', 'dishs_id')->withPivot('id', 'categories_id', 'dishs_id');;
    }
}

and my controller :

     $dish_by_category = Category::with('dishes')->get();
      dd($dish_by_category);

and when i display this i have :

Illuminate\Database\Eloquent\Collection {#297 ▼
  #items: array:2 [▼
    0 => App\Category {#314 ▼
      #table: "categories"
      #connection: "mysql"
      #primaryKey: "id"
      #keyType: "int"
      +incrementing: true
      #with: []
      #withCount: []
      #perPage: 15
      +exists: true
      +wasRecentlyCreated: false
      #attributes: array:6 [▶]
      #original: array:6 [▶]
      #changes: []
      #casts: []
      #classCastCache: []
      #dates: []
      #dateFormat: null
      #appends: []
      #dispatchesEvents: []
      #observables: []
      #relations: array:1 [▼
        "dishes" => Illuminate\Database\Eloquent\Collection {#322 ▼
          #items: array:1 [▼
            0 => App\Dishs {#327 ▶}
          ]
        }
      ]
      #touches: []
      +timestamps: true
      #hidden: []
      #visible: []
      #fillable: []
      #guarded: array:1 [▶]
    }

But i have 3 dish for category and not one....

Ty

Activity icon

Replied to Display Relation Belong To Many

@snapey if i see only one dish maybe its because i use belongtomany and not hasmany ?

when i change belongtomany to HasMany i have this error :

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'dishs.category_dishes' in 'where clause' (SQL: select * from `dishs` where `dishs`.`category_dishes` in (?)) 
Activity icon

Replied to Display Relation Belong To Many

@shez1983 i dont add dish with form, and pivot table at the same time

              public function store(Request $request, $restaurant)
    {


        $restaurant = Restaurants::find($restaurant);

		 $Dishs = new Dishs(); 
	     $Dishs ->id_restaurant = $restaurant ->id;  
	     $Dishs ->name = request("name");  
	     $Dishs ->price = request("price");  
	     $Dishs ->description = request("description");  
	     $Dishs ->image = request("description");  



        if($request->file('image')){

        	   $originalImage= $request->file('image');
          $thumbnailImage = Image::make($originalImage);
          $thumbnailPath = public_path().'/images/';
                $thumbnailImage->resize(600, null, function ($constraint) {
    	   $constraint->aspectRatio();
     	       });
           $rand = rand(1,100000);
     	     $thumbnailImage->save($thumbnailPath.$rand.$originalImage->getClientOriginalName()); 

      
      $Dishs->image = $rand.$originalImage->getClientOriginalName();
      }
	    	     $Dishs ->save();


foreach(request("categorybox") as $category_id)
{
    $category_dish = new category_dish();
    $category_dish->category_id = $category_id;
    $category_dish->dish_id = $Dishs->id;
    $category_dish->save();

}
    return back();

so if i have a line on pivot table i have dish and category

@snapey yes i have

id	id_restaurant	name		price	description	image	
1 		1 	Burger1 	10		aaa 		1711oe.jpg 	
2 		1 	Burger2 	10 		rh 			816nvoe.jpg 	
3 		1 	Burger3 	10 		azf 			2275benvoe.jpg 	
4 		1 	Burger4 	10 		eg 			51oe.jpg 	
5 		1 	Burger5 	10 		fe 			326oe.jpg 	
6 		1 	Pizza 		10 		fe 			21e.jpg 	

Mar
28
1 week ago
Activity icon

Replied to Display Relation Belong To Many

@snapey

oh yes no its mb, but i have question i add more dish but i didn't see it, why ?


Illuminate\Database\Eloquent\Collection {#303 ▼
  #items: array:3 [▼
    0 => App\Category {#316 ▶}
    1 => App\Category {#317 ▼
      #table: "categories"
      #connection: "mysql"
      #primaryKey: "id"
      #keyType: "int"
      +incrementing: true
      #with: []
      #withCount: []
      #perPage: 15
      +exists: true
      +wasRecentlyCreated: false
      #attributes: array:6 [▼
        "id" => 2
        "id_restaurant" => "1"
        "name" => "burger"
        "icon" => "fastfood"
        "created_at" => "2020-03-28 18:55:34"
        "updated_at" => "2020-03-28 18:55:34"
      ]
      #original: array:6 [▶]
      #changes: []
      #casts: []
      #classCastCache: []
      #dates: []
      #dateFormat: null
      #appends: []
      #dispatchesEvents: []
      #observables: []
      #relations: array:1 [▼
        "Dishes" => Illuminate\Database\Eloquent\Collection {#325 ▼
          #items: array:1 [▼
            0 => App\Dishs {#330 ▶}
          ]
        }
      ]
      #touches: []
      +timestamps: true
      #hidden: []
      #visible: []
      #fillable: []
      #guarded: array:1 [▶]
    }
    2 => App\Category {#318 ▶}
  ]
}


On the category Burger the relation have only one array on this dd

BUT if i see my database, i have more dish on this category:

id	category_id	dish_id	
1 		1 			2 	
2 		3 			3 	
3 		1 			4 	
4 		2 			4 	
5 		2 			5 	
6 		1 			6 	

On the category 2 we can see 2 dish ( id 4-5) and dd display only one and not the good

Activity icon

Replied to Display Relation Belong To Many

@snapey

yes

I just refreshed and now I see the associated dish .. I don't understand why it works now

Illuminate\Database\Eloquent\Collection {#303 ▼
  #items: array:3 [▼
    0 => App\Category {#316 ▶}
    1 => App\Category {#317 ▶}
    2 => App\Category {#318 ▼
      #table: "categories"
      #connection: "mysql"
      #primaryKey: "id"
      #keyType: "int"
      +incrementing: true
      #with: []
      #withCount: []
      #perPage: 15
      +exists: true
      +wasRecentlyCreated: false
      #attributes: array:6 [▶]
      #original: array:6 [▶]
      #changes: []
      #casts: []
      #classCastCache: []
      #dates: []
      #dateFormat: null
      #appends: []
      #dispatchesEvents: []
      #observables: []
      #relations: array:1 [▼
        "Dishes" => Illuminate\Database\Eloquent\Collection {#322 ▼
          #items: array:1 [▼
            0 => App\Dishs {#327 ▼
              #table: "dishs"
              #connection: "mysql"
              #primaryKey: "id"
              #keyType: "int"
              +incrementing: true
              #with: []
              #withCount: []
              #perPage: 15
              +exists: true
              +wasRecentlyCreated: false
              #attributes: array:8 [▼
                "id" => 3
                "id_restaurant" => "1"
                "name" => "s"
                "price" => "zaf"
                "description" => "azf"
                "image" => "22756chatbenvoe.jpg"
                "created_at" => "2020-03-28 19:43:08"
                "updated_at" => "2020-03-28 19:43:08"
              ]

But now i need to add where for recover only the good dish.. but how i can access at this ?

Activity icon

Replied to Display Relation Belong To Many

just idk how display this, because my dish is empty when i test this :

 $dish_by_category = Category::with('Dishes')->get();
  dd($dish_by_category);
Activity icon

Replied to Display Relation Belong To Many

@snapey

oh but i have data on my pivot table :

id	category_id		dish_id	
2 		4 			  9 	
3 		3 			  10 	
4 		3 			  11 	
5 		4 			  11
6 		5 			  11 	
7 		3 			  12 	
8 		4 			  13 	
9 		5 			  14 	
10 		3 			  15 	
	
Activity icon

Replied to Display Relation Belong To Many

@snapey

i need id_restaurant for other function

no i have nothing on my pivot_table:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\Pivot;
class category_dish extends Model
{
    //
}

that change what to add this : unsigned(); ?

and so i need to change what for display the good dish for the good category ?

Ty

Activity icon

Started a new Conversation Display Relation Belong To Many

Hello,

I have a little problem, i have relation between table ( dish / category and pivot table ) And my problem is to display the good dish on the good category :

My Database :


    public function up()
    {
        Schema::create('dishs', function (Blueprint $table) {
            $table->id();
            $table->string("id_restaurant");
            $table->string("name");
            $table->string("price");
            $table->string("description");
            $table->string("image");
            $table->timestamps();
        });
    }


    public function up()
    {
        Schema::create('category_dishes', function (Blueprint $table) {
            $table->id();
            $table->string("category_id");
            $table->string("dish_id");
            $table->timestamps();
        });
    }

    public function up()
    {
        Schema::create('categories', function (Blueprint $table) {
            $table->id();
            $table->string("id_restaurant");
            $table->string("name");
            $table->string("icon");
            $table->timestamps();
        });
    }





My Model :

class Dishs extends Model
{
    protected $table = 'dishs';

    public function Category()
    {
        return $this->belongsToMany('App\Category', 'category_dishes', 'category_id', 'dish_id');
    }
}




class Category extends Model
{
    protected $table = 'categories';

        public function Dishes()
    {
        return $this->belongsToMany('App\Dishs', 'category_dishes', 'dish_id', 'category_id');
    }
}

my controller

        $dish_by_category = Category::with('Dishes')->get();
      dd($dish_by_category);

But i have this :

Illuminate\Database\Eloquent\Collection {#304 ▼
  #items: array:4 [▼
    0 => App\Category {#317 ▶}
    1 => App\Category {#318 ▶}
    2 => App\Category {#319 ▼
      #table: "categories"
      #connection: "mysql"
      #primaryKey: "id"
      #keyType: "int"
      +incrementing: true
      #with: []
      #withCount: []
      #perPage: 15
      +exists: true
      +wasRecentlyCreated: false
      #attributes: array:6 [▶]
      #original: array:6 [▶]
      #changes: []
      #casts: []
      #classCastCache: []
      #dates: []
      #dateFormat: null
      #appends: []
      #dispatchesEvents: []
      #observables: []
      #relations: array:1 [▼
        "Dishes" => Illuminate\Database\Eloquent\Collection {#321 ▼
          #items: []
        }
      ]
      #touches: []
      +timestamps: true
      #hidden: []
      #visible: []
      #fillable: []
      #guarded: array:1 [▼
        0 => "*"
      ]
    }
    3 => App\Category {#320 ▶}
  ]
}

The dish is empty ;/

If you can help me

Ty

Mar
27
1 week ago
Activity icon

Replied to Has Many Relation

no one know why its again empty ?

Activity icon

Replied to Has Many Relation

@brjig

oh yes mb, i want display the good dish of the category

But i have again nothing:

Illuminate\Database\Eloquent\Collection {#304 ▼
  #items: array:4 [▼
    0 => App\Category {#317 ▶}
    1 => App\Category {#318 ▶}
    2 => App\Category {#319 ▼
      #table: "categories"
      #connection: "mysql"
      #primaryKey: "id"
      #keyType: "int"
      +incrementing: true
      #with: []
      #withCount: []
      #perPage: 15
      +exists: true
      +wasRecentlyCreated: false
      #attributes: array:6 [▶]
      #original: array:6 [▶]
      #changes: []
      #casts: []
      #classCastCache: []
      #dates: []
      #dateFormat: null
      #appends: []
      #dispatchesEvents: []
      #observables: []
      #relations: array:1 [▼
        "Dishes" => Illuminate\Database\Eloquent\Collection {#321 ▼
          #items: []
        }
      ]
      #touches: []
      +timestamps: true
      #hidden: []
      #visible: []
      #fillable: []
      #guarded: array:1 [▶]
    }
    3 => App\Category {#320 ▶}
  ]
}

with this :

$dish_by_category = Category::with('Dishes')->get();

Activity icon

Replied to Has Many Relation

@brjig ye ty, i have no error now, but when i test with this :

      $dish_by_category = Dishs::with('category')->get();
      dd($dish_by_category);

i have this but category is empty

Illuminate\Database\Eloquent\Collection {#304 ▼
  #items: array:4 [▼
    0 => App\Dishs {#317 ▶}
    1 => App\Dishs {#318 ▶}
    2 => App\Dishs {#319 ▶}
    3 => App\Dishs {#320 ▼
      #table: "dishs"
      #connection: "mysql"
      #primaryKey: "id"
      #keyType: "int"
      +incrementing: true
      #with: []
      #withCount: []
      #perPage: 15
      +exists: true
      +wasRecentlyCreated: false
      #attributes: array:8 [▶]
      #original: array:8 [▶]
      #changes: []
      #casts: []
      #classCastCache: []
      #dates: []
      #dateFormat: null
      #appends: []
      #dispatchesEvents: []
      #observables: []
      #relations: array:1 [▼
        "category" => Illuminate\Database\Eloquent\Collection {#307 ▼
          #items: []
        }
      ]
      #touches: []
      +timestamps: true
      #hidden: []
      #visible: []
      #fillable: []
      #guarded: array:1 [▶]
    }
  ]
}

Activity icon

Replied to Has Many Relation

@cliffordatcaveodotnl

yes but when i have create the model category_dish i have migration category_dishes:

C:\laragon\www\restaurant>php artisan make:model category_dish -m Model created successfully. Created Migration: 2020_03_26_132709_create_category_dishes_table

Activity icon

Replied to Has Many Relation

yes but its not the problem no ?

Activity icon

Replied to Has Many Relation

no one ?

Activity icon

Replied to Has Many Relation

@brjig idk what you want i change on my code

Activity icon

Replied to Has Many Relation

my database is like this :

    public function up()
    {
        Schema::create('dishs', function (Blueprint $table) {
            $table->id();
            $table->string("id_restaurant");
            $table->string("name");
            $table->string("price");
            $table->string("description");
            $table->string("image");
            $table->timestamps();
        });
    }



    public function up()
    {
        Schema::create('categories', function (Blueprint $table) {
            $table->id();
            $table->string("id_restaurant");
            $table->string("name");
            $table->string("icon");
            $table->timestamps();
        });
    }


    public function up()
    {
        Schema::create('category_dishes', function (Blueprint $table) {
            $table->id();
            $table->string("category_id");
            $table->string("dish_id");
            $table->timestamps();
        });
    }
Mar
26
1 week ago
Activity icon

Started a new Conversation Has Many Relation

Hello,

I have 3 table ( dish / category and pivot table category_dish )

One dish can be to belong at many category.

So on my pivot table i save the id_category and id_dish

But when i want display the good dish on the good category i have error...

My code :

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Dishs extends Model
{
        public function Category()
    {
          return $this->belongsToMany('App\Category', 'category_dish');
    }
}

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Category extends Model
{
    public function Dishs()
    {
        return $this->HasMany('App\Dishs', 'category_dish');
    }
}

My controller :

$dish_by_category = Dishs::with('category')->get();

and i have this error :

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'restaurant.category_dish' doesn't exist (SQL: select categories.*, category_dish.dishs_id as pivot_dishs_id, category_dish.category_id as pivot_category_id from categories inner join category_dish on categories.id = category_dish.category_id where category_dish.dishs_id in (5, 6, 7, 8, 9, 10, 11, 12))

Ty for your help

Activity icon

Replied to Checkbox Insert

oh yes ty :)

Activity icon

Started a new Conversation Checkbox Insert

Hello,

I have form, with checkbox, but i want register all case checked but idk how..

My code html:

  				@foreach($categorylist as $categorylist)
  					<input type="radio"  name="categorybox[]"  value="{{$categorylist->id}}" class="checkbox">	{{$categorylist->name}}		
  				@endforeach

and my controller

	     $category_dish = new category_dish();
	     $category_dish->category_id = request("categorybox");
	     $category_dish->dish_id = $Dishs->id;
	     $category_dish->save();

Ty

Mar
05
1 month ago
Activity icon

Awarded Best Reply on Connect Table

ok that work i remplace -> get by -> first

Activity icon

Replied to Connect Table

ok that work i remplace -> get by -> first

Activity icon

Replied to Connect Table

I need to use method update if i want update my table no ?

i change my code like this :


        $idevent = $participant->evenement_id;


   $events = Evenement::where('id', $idevent) ->get();
       $goodnbrplace = $events[0] -> nbrPlace;

            if ($goodnbrplace === "illimité")
         {
            $events -> nbrPlace = "illimité";
            $events  -> update();
         }


         if ($goodnbrplace != "illimité")
         {
           $goodnbrplacenoillimite = $goodnbrplace + 1;
           $events -> nbrPlace = $goodnbrplacenoillimite;
           $events  -> update();
         }


But i have this error now :

Method Illuminate\Database\Eloquent\Collection::save does not exist.

Activity icon

Started a new Conversation Connect Table

Hello

I have table Evenement, and i want update this table on my controller :



    public function destroy(Participant $participant, ParticipantbyEvent $ParticipantbyEvent, Evenement $event)
    {

	.....

        $idevent = $participant->evenement_id;

            if ($goodnbrplace === "illimité")
         {
            $event -> nbrPlace = "illimité";
            $event  -> update(array('id' => $idevent));
         }


         if ($goodnbrplace != "illimité")
         {
           $goodnbrplacenoillimite = $goodnbrplace + 1;
           $event -> nbrPlace = $goodnbrplacenoillimite;
           $event  -> update(array('id' => $idevent));
         }



     return redirect('/eventsub');
    }

But idk why, when i try dd($event) i have no connection on my table Evenement...

Ty

Mar
03
1 month ago
Activity icon

Started a new Conversation Webcam

Hello,

I want use my webcam for scan QR code, my script work, but when i use my script on my project laravel that dont work, i cant active my webcam, he dont purpuse me this option ...

I have this ;

Webcam.js Error: No supported webcam interface found.

Feb
20
1 month ago
Activity icon

Replied to Synthaxe Where

ye its that ty, its OrWhere i try just OR but that dont work ;(

TY :)

Activity icon

Started a new Conversation Synthaxe Where

Hello,

I have a little problem with my where :

that work correctly :

         $event = Evenement::where([
            ['categorie_user', $user -> categorie_user ],
            ])->whereNotIn('id', $participantselect->pluck('evenement_id')) ->get();

But that no:

     $event = Evenement::where([
        ['categorie_user', $user -> categorie_user ],
        ['categorie_user',"Public" ],
        ])->whereNotIn('id', $participantselect->pluck('evenement_id')) ->get();

what is the error ?

TY

Feb
12
1 month ago
Activity icon

Started a new Conversation Qr Code Reader

Hello,

I have a question, i want create a QR Code reader, i search but i dont find librairie Laravel for this. do you know a good library for a qr code reader?

Ty

Feb
05
2 months ago
Activity icon

Replied to Foreach Object On Controller

ye i see after sry

that work good, ty :))

Activity icon

Replied to Foreach Object On Controller

@ahmeddabak

Ty but i have a problem, my problem is when someone subscribe at an event, i want delete hit of the list, but with this code :

['id', '!=', $participantselect->pluck('evenement_id')->toArray()],

only the first event whitch is subscribe is delete of the list ...

Activity icon

Started a new Conversation Foreach Object On Controller

Hello ,

i dont know if is possible, but i would like foreach my object on my controller...

My code :


    public function index()
    {
    
         $user = Auth::user();
 
         $participantselect = Participant::where('user_id', '=', $user-> id) -> get();
     

         $event = Evenement::where([
            ['categorie_user', '=', $user -> categorie_user],
            ['id', '!=', $participantselect[3] -> evenement_id],
        ]) ->get();
         

        return view('user/subevent.index',
         ['data' => $event]
    );
    }


i would like ['id', '!=', $participantselect[0,1,2,3,4,5,6,7,8,9,10... n] -> evenement_id], but how ?

Ty

Feb
04
2 months ago
Activity icon

Replied to Belong To Many

ye ye i find it this after my message sry

That work good now

Ty all for your help

Activity icon

Replied to Belong To Many

i try this ;


<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Participant extends Model
{
    //
}


<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Evenement extends Model
{
        public function users()
    {
        return $this->hasMany('App\Users');
    }
}

<?php

namespace App;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

class User extends Authenticatable
{


            public function evenements()
    {
        return $this->belongsToMany('App\Evenement', 'participants');
    }
}

and on my controller :

public function index() 
{
  $user = User::with('evenements')->find(auth()->user()->id);

  dd($user);
  return view('user/eventuser.index',compact('user'));
}

and on my dd($user); i see that :

App\User {#329 ▼
  #guarded: []
  #hidden: array:2 [▶]
  #casts: array:1 [▼
    "email_verified_at" => "datetime"
  ]
  #connection: "mysql"
  #table: "users"
  #primaryKey: "id"
  #keyType: "int"
  +incrementing: true
  #with: []
  #withCount: []
  #perPage: 15
  +exists: true
  +wasRecentlyCreated: false
  #attributes: array:14 [▶]
  #original: array:14 [▶]
  #changes: []
  #dates: []
  #dateFormat: null
  #appends: []
  #dispatchesEvents: []
  #observables: []
  #relations: array:1 [▼
    "evenements" => Illuminate\Database\Eloquent\Collection {#336 ▼
      #items: array:4 [▼
        0 => App\Evenement {#339 ▶}
        1 => App\Evenement {#342 ▶}
        2 => App\Evenement {#343 ▶}
        3 => App\Evenement {#344 ▶}
      ]
    }
  ]
  #touches: []
  +timestamps: true
  #visible: []
  #fillable: []
  #rememberTokenName: "remember_token"
}

so i have the good relation, but idk how display on my view the relation

(

#relations: array:1 [▼
    "evenements" => Illuminate\Database\Eloquent\Collection {#336 ▼
      #items: array:4 [▼
        0 => App\Evenement {#339 ▶}
        1 => App\Evenement {#342 ▶}
        2 => App\Evenement {#343 ▶}
        3 => App\Evenement {#344 ▶}
      ]

)

Activity icon

Replied to Belong To Many

@snapey

Laravel Framework 6.6.1

Activity icon

Replied to Belong To Many

@htin-lynn with your code i have the same error

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'projet-tutore.evenement_user' doesn't exist (SQL: select evenements.*, evenement_user.user_id as pivot_user_id, evenement_user.evenement_id as pivot_evenement_id from evenements inner join evenement_user on evenements.id = evenement_user.evenement_id where evenement_user.user_id in (2))

Feb
03
2 months ago
Activity icon

Replied to Belong To Many

i add this but again the same error :/

@snapey

Activity icon

Replied to Belong To Many

ok:


<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Evenement extends Model
{
    public function users()
    {
        return $this->belongsToMany('App\Users')->using('App\Participant');
    }
}



    public function evenements()
    {
        return $this->belongsToMany('App\Evenement')->using('App\Participant');
    }

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Participant extends Pivot
{
    //
}

@snapey

Activity icon

Replied to Belong To Many

oh yes sry i tired today.. and yes i will see laravel from scratch, i m again begginer :/

i think we have a problem with the pivot, bc i have this error :

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'projet-tutore.evenement_user' doesn't exist (SQL: select evenements.*, evenement_user.user_id as pivot_user_id, evenement_user.evenement_id as pivot_evenement_id from evenements inner join evenement_user on evenements.id = evenement_user.evenement_id where evenement_user.user_id in (2))

@snapey

Activity icon

Replied to Belong To Many

ok ty for your reply, i have change all my class, add the foreach on my view, and this on my controller:

       public function index()
    {
        $user->load('evenements');
        return view('user/eventuser.index',
        ['evenements' => $user]
    );

    }

but i have this error :

Undefined variable: user

Activity icon

Replied to Belong To Many

@snapey yes i see the convention for pivot table to late ...

Ye i think my table participants is active, but idk how use it on my controller ?


       public function index()
    {
        return view('user/eventuser.index');
    }      

Activity icon

Replied to Belong To Many

ok i change my class.

But on my controller i add what ?

and i dont understand that : $evenements = $user->comments;

Activity icon

Started a new Conversation Belong To Many

Hi

i have 3 table :

the table user :


    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name');
            $table->string('firstname');
            $table->string('email')->unique();
            $table->timestamp('email_verified_at')->nullable();
            $table->string('password');
            $table->string('categorie_user');
            $table->string('droit');
            $table->string('phone');
            $table->string('blocked');
            $table->date('date_evenement');
            $table->rememberToken();
            $table->timestamps();

        });
    }

the table evenement :


    public function up()
    {
        Schema::create('evenements', function (Blueprint $table) {
    $table->bigIncrements('id');
    $table->string('categorie_id');
    $table->string('categorie_user');
    $table->string('name');
    $table->string('description');
    $table->string('ville');
    $table->string('rue');
    $table->date('date_evenement');
     $table->string('heure');
     $table->mediumText('image')->nullable();
    $table->timestamps();
        });
    }


and the table participant:

public function up()
{
    Schema::create('participants', function (Blueprint $table) {
$table->bigIncrements('id');
$table->integer('user_id');
$table->integer('evenement_id');
$table->timestamps();
    });
}

When a user subscribe at an event i save his id and the id of event of my table participant.

But after i want display the event whitch the user as subscribe. So i need to use belong to many. So i add this :

class User extends Authenticatable
{
    
            public function evenements()
    {
        return $this->belongsToMany('App\Evenement');
    }

}

and this :

class Evenement extends Model
{
        public function users()
    {
        return $this->belongsToMany('App\Users');
    }
}

but how display the event information ??

Ty

Activity icon

Started a new Conversation Pivot Table

Hello,

I have 2 table:

the first table is evenement, and the second is user. When one user subscribe on one event, i save it on the pivot table "participant" and i save the id_user and the id_evenement.

But after i want display the list of event whitch the user participle but idk how do that ...

I add this :

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Evenement extends Model
{
        public function users()
    {
        return $this->belongsToMany('App\Users');
    }
}

but after  i m blocked...

Ty

Jan
24
2 months ago
Activity icon

Started a new Conversation Checkbox Save Laracast

hello,

I have one question:

I have table useradd, and on this table i want add data by a checkbox, but how i can register all checkbox check ?

TY

Jan
19
2 months ago
Activity icon

Replied to Resize Image Before Save

yes but if the original photo is in landscape mode I want to keep the dimensions of a photo in landscape mode, and if it is in portrait I want it to keep the dimensions of a photo in portrait. I would not like the size of the resizing to be fixed

Activity icon

Replied to Resize Image Before Save

ok that work good, but i have question, can we recover the witdh and height of the photo posted ?

because if the image = 3000 * 4500 i want resize to 300 *450, but if image = 4500*3000 i want 450*350