now can blast me if i'm asking question specifically, saying laravel, i'm wondering, efficient way of chaining 2 data sets tools within laravel.
is there specific mindset should using when picking between using eloquent relationships , joins query builder? or drawbacks using query builder on smaller or larger datasets should consider?
i'm building ticket system need 1 or 2 fields user table , seems on top consider using relationship @ point if needs of system increases, lead messy code. situation relationships there solve?
is there coupling type action happening when using eloquent relationships should aware of?
if i'm not being clear how i'm asking question try , reword it.
i think you'll find did setting couple simple relationship methods in eloquent model unleashes power (and ease , simplicity) of eloquent. example, rather write custom join code or use structure this:
foreach($user->tickets $ticket) { ... etc ... }
it sounds you're new laravel. highly recommend reading pages on relationships in laravel manual. there many great examples. there laracast video tutorial on relationships here. have no affiliation site.
ticket class:
<?php class ticket extends model { public function user() { return $this->belongsto('user'); } }
user class:
<?php class user extends model { public function tickets() { return $this->hasmany('ticket'); } }
so long have tables setup so:
tickets (table) - id - user_id users (table) - id
this example assumes models in global namespace. can grab user data ticket so:
$ticket->user->first_name $ticket->user->last_name
Comments
Post a Comment