Acess belongsTo by where
up vote
-2
down vote
favorite
I got this code:
public function Locate($name)
$locate= Products::where('name', 'like', "$name%") ->get();
return response()->json($locate, 200);
I want to access belongsTo by this $name and put it in json
Here is my model:
class Products extends Model
protected $fillable = ['name', 'code', 'price'];
protected $hidden = ['id'];
public function Group()
return $this->belongsTo('ApppGroup', 'product_id', 'id');
json laravel
add a comment |
up vote
-2
down vote
favorite
I got this code:
public function Locate($name)
$locate= Products::where('name', 'like', "$name%") ->get();
return response()->json($locate, 200);
I want to access belongsTo by this $name and put it in json
Here is my model:
class Products extends Model
protected $fillable = ['name', 'code', 'price'];
protected $hidden = ['id'];
public function Group()
return $this->belongsTo('ApppGroup', 'product_id', 'id');
json laravel
add a comment |
up vote
-2
down vote
favorite
up vote
-2
down vote
favorite
I got this code:
public function Locate($name)
$locate= Products::where('name', 'like', "$name%") ->get();
return response()->json($locate, 200);
I want to access belongsTo by this $name and put it in json
Here is my model:
class Products extends Model
protected $fillable = ['name', 'code', 'price'];
protected $hidden = ['id'];
public function Group()
return $this->belongsTo('ApppGroup', 'product_id', 'id');
json laravel
I got this code:
public function Locate($name)
$locate= Products::where('name', 'like', "$name%") ->get();
return response()->json($locate, 200);
I want to access belongsTo by this $name and put it in json
Here is my model:
class Products extends Model
protected $fillable = ['name', 'code', 'price'];
protected $hidden = ['id'];
public function Group()
return $this->belongsTo('ApppGroup', 'product_id', 'id');
json laravel
json laravel
edited Nov 9 at 20:32
asked Nov 9 at 18:49
SkullFire
185
185
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
If you want to get a relationship :
$locate= Products::where('name', 'like', "$name%")->with('group')->get();
There is. I got one another question. Is there a way to access the foreign key inside this relashionp and return in json? If i use your code, the json return all group, but with foreign key numbers
– SkullFire
Nov 9 at 20:22
This returns "NULL" but if use hasOne, works fine
– SkullFire
Nov 9 at 21:48
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
If you want to get a relationship :
$locate= Products::where('name', 'like', "$name%")->with('group')->get();
There is. I got one another question. Is there a way to access the foreign key inside this relashionp and return in json? If i use your code, the json return all group, but with foreign key numbers
– SkullFire
Nov 9 at 20:22
This returns "NULL" but if use hasOne, works fine
– SkullFire
Nov 9 at 21:48
add a comment |
up vote
2
down vote
If you want to get a relationship :
$locate= Products::where('name', 'like', "$name%")->with('group')->get();
There is. I got one another question. Is there a way to access the foreign key inside this relashionp and return in json? If i use your code, the json return all group, but with foreign key numbers
– SkullFire
Nov 9 at 20:22
This returns "NULL" but if use hasOne, works fine
– SkullFire
Nov 9 at 21:48
add a comment |
up vote
2
down vote
up vote
2
down vote
If you want to get a relationship :
$locate= Products::where('name', 'like', "$name%")->with('group')->get();
If you want to get a relationship :
$locate= Products::where('name', 'like', "$name%")->with('group')->get();
answered Nov 9 at 19:28
Nick Surmanidze
865517
865517
There is. I got one another question. Is there a way to access the foreign key inside this relashionp and return in json? If i use your code, the json return all group, but with foreign key numbers
– SkullFire
Nov 9 at 20:22
This returns "NULL" but if use hasOne, works fine
– SkullFire
Nov 9 at 21:48
add a comment |
There is. I got one another question. Is there a way to access the foreign key inside this relashionp and return in json? If i use your code, the json return all group, but with foreign key numbers
– SkullFire
Nov 9 at 20:22
This returns "NULL" but if use hasOne, works fine
– SkullFire
Nov 9 at 21:48
There is. I got one another question. Is there a way to access the foreign key inside this relashionp and return in json? If i use your code, the json return all group, but with foreign key numbers
– SkullFire
Nov 9 at 20:22
There is. I got one another question. Is there a way to access the foreign key inside this relashionp and return in json? If i use your code, the json return all group, but with foreign key numbers
– SkullFire
Nov 9 at 20:22
This returns "NULL" but if use hasOne, works fine
– SkullFire
Nov 9 at 21:48
This returns "NULL" but if use hasOne, works fine
– SkullFire
Nov 9 at 21:48
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53231691%2facess-belongsto-by-where%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown