Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -tabel user
- id
- name
- email
- pass
- role
- -tabel client
- id
- client_name
- client_company
- adress
- email
- website
- users_id
- -tabrl project
- id
- project_name
- project_detail
- project_type
- budget
- is_hour
- total_hour
- start_date
- end_date
- client_id
- ////////model////////
- Proejct.php
- <?php
- namespace App;
- use Illuminate\Database\Eloquent\Model;
- class Project extends Model
- {
- protected $table = 'project';
- public $timestamps = false;
- protected $fillable = [
- 'name',
- 'client_id'
- ];
- public function Client()
- {
- return $this->belongsTo('App\Clients');
- }
- }
- Clients.php
- <?php
- namespace App;
- use Illuminate\Database\Eloquent\Model;
- class Clients extends Model
- {
- public $timestamps = false;
- protected $table = 'client';
- protected $fillable = [
- 'client_name',
- 'client_company',
- 'adress',
- 'email',
- 'website'
- ];
- public function project()
- {
- return $this->hasMany('App\Project');
- }
- public function user()
- {
- return $this->belongsTo('App\User');
- }
- }
- User.php
- <?php
- namespace App;
- use Illuminate\Foundation\Auth\User as Authenticatable;
- class User extends Authenticatable
- {
- protected $table = 'users';
- /**
- * The attributes that are mass assignable.
- *
- * @var array
- */
- protected $fillable = [
- 'name', 'email', 'password', 'role',
- ];
- /**
- * The attributes that should be hidden for arrays.
- *
- * @var array
- */
- protected $hidden = [
- 'password', 'remember_token',
- ];
- public function client()
- {
- return $this->hasOne('App\Clients');
- }
- }
- ProjectController
- <?php
- namespace App\Http\Controllers;
- use Illuminate\Http\Request;
- use App\Http\Requests;
- use App\Project;
- use App\Clients;
- use App\User;
- class ProjectController extends Controller
- {
- public function index()
- {
- $Pr = Project::all();
- return view('project.index', ['project' => $Pr]);
- }
- }
- buat nampilin nya
- foreach ($project as $projects) {
- <td>{{ $projects->client->users->name }}</td>
- }
Add Comment
Please, Sign In to add comment