I want to get the title, description, and price which are stored in a pivot table between users and services called userservices. I want to be able to display this information I'll get from the userservices table, inside the user profile view page.
I have 4 tables for that which include,
A User table with id, name, surname, email, phone, area_id.
A Service table with id, name, description, and category_id.
A category table with id, name, description
and I have pivot table btw users and services called userservices which stores the service_id, user_id, title, description and price
I wish to know how can I get the title, description and price for a service that belongs to a particular user, provided the information exists in the userservice table in the database using Laravel.
In my user Controller, I did something like this
public function jobberDetails($id) {
$profiledetail = User::with('area.town.region.country')
->with('userservice')
->find($id);
DB::update("UPDATE users SET visit = visit + 1 WHERE id = '$id'");
// dd($jobdetail);
return view('Users.profileDetail', compact('profiledetail'));
}
in my web file
// Route qui permet d'afficher,le profil d'un Jobbeur
Route::get('/jobber/profiledetails/{id}', 'UserController@jobberDetails')->where(array('id' => '[0-9]+'))->name('profileDetails');
In my model I did something like this
public function area(): BelongsTo
{
return $this->belongsTo(Area::class);
}
public function getTownAttribute(): Town
{
return $this->area->town;
}
public function getRegionAttribute(): Region
{
return $this->area->town->region;
}
public function getCountryAttribute(): Country
{
return $this->area->town->region->country;
}
public function userservice(): BelongsTo
{
return $this->belongsTo(UserServices::class);
}
and in my profile detail blade I did this
<div class="row">
<div class="col-lg-8">
<div class="job-single-head3">
<div class="job-single-info3">
<h3> </h3>
<span><i class="la la-map-marker"></i>, </span>
<span class="job-is ft" id="more" onclick="$('.details').slideToggle(function(){$('#more').html($('.details').is(':visible')?'Cacher le numero':'Voir le numero');});">Voir le numero</span>
</div>
</div><!-- Job Head -->
</div>
</div>
</div>
<div class="job-wide-devider">
<div class="row">
<div class="col-lg-8 column">
<div class="extra-job-info details" style="display:none">
<p style="text-align: center; padding: 10px; font-size: 45px;"><i class="la la-phone"></i> </p>
</div>
<div class="job-details">
<h3>Description</h3>
<p> .</p>
<h3>Conditions et tarifs</h3>
<ul>
<li></li>
</ul>
<h3>Title</h3>
<ul>
<li></li>
</ul>
</div>
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2Jcx3vP
via IFTTT
Aucun commentaire:
Enregistrer un commentaire