how can get a specific value from database in using php laravel model
Get the solution ↓↓↓function subscriptionpack(Request $request)
{
$sub = subscription::all();
$details = $sub['details'];
dump('$details');
}
I can get all values from this code, but I can't get the specific field that named details. When I calldump($sub
) it was shown all details, but thedump('$details')
make an error that is undefined index:details
anyone can help me to correct this code?
Answer
Solution:
You can use select method to selectspecific
column data :
$sub = subscription::select('details')->get();
Or, you can do with on get() method as like :
$sub = subscription::get(['details']);
Answer
Solution:
If you need single column from the result set usepluck
$subs = subscription::all();
$details = $subs->pluck('details')->toArray();
Answer
Solution:
You can either loop over to your collection e.g
foreach($sub as $s){
dump($s->details)
}
or you can try something like.
$sub->first()->details
but this will give you only first details element from your collection.
Answer
Solution:
First a model should be in singular, no spacing between words, and capitalised.
You should useSubscription::all();
notsubscription::all();
. You should read Laravel conventions
use App\Subscription;
..
function subscriptionpack(Request $request)
{
$sub = Subscription::all()->pluck('details');
dd($sub);
}
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: deprecated: directive 'allow_url_include' is deprecated in unknown on line 0
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.