jeudi 23 novembre 2017

How can I display all jobs and every job has it own company in one to many relationship in laravel?

I try to build my own project which is job online website.

I have two tables company and job.Table company can have many jobs relationship

Here is relationship

//company.php
public function jobs(){
    return $this->hasMany(Job::class);
}
//job.php
public function company(){
        return $this->belongsTo(Company::class);
    }

​My tables

Schema::create('companies', function (Blueprint $table) {
    $table->increments('id');
    $table->integer('user_id');
    $table->string('companyName');
    $table->string('logo')->nullable();
    $table->string('contactPerson');
    $table->string('employeeSize');
​    ...

Schema::create('jobs', function (Blueprint $table) {
    $table->increments('id');
    $table->integer('company_id');
    $table->string('jobTitle');
    $table->longText('jobDescription');
    $table->longText('jobRequirement');
    $table->date('deadline');
​    ...

​ I want to display all jobs and every job has its own company like

  1. +in every list of the job must have
    • jobTitle,
    • deadline,..and
    • companyName, logo

what is the code in controller and in the view would be? please help!



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2hLpKzr
via IFTTT

Aucun commentaire:

Enregistrer un commentaire