Skip to content

Instantly share code, notes, and snippets.

@segun6060
Last active March 8, 2017 19:53
Show Gist options
  • Save segun6060/de4952a4f96197a93de349d81e5f6bee to your computer and use it in GitHub Desktop.
Save segun6060/de4952a4f96197a93de349d81e5f6bee to your computer and use it in GitHub Desktop.
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Message extends Model
{
public function user()
{
return $this->belongsTo('App\User','id');
}
}
public function index()
{
$user = User::has('message')->get();
$user = User::has('collector')->get();
return view('home', $user)->with('user', $user);
}
public function up()
{
Schema::create('messages', function (Blueprint $table) {
$table->increments('id');
$table->integer('userid');
$table->string('name');
$table->string('amount');
$table->string('acname');
$table->string('bname');;
$table->string('acnumber');
$table->string('actype');
$table->string('phone');
$table->timestamps();
});
}
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password','phone','plan','bname','acname','acnumber','actype',
];
protected $table = 'users';
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
public function message()
{
return $this->hasOne('App\Message','user_id');
}
}
@unless(is_null(Auth::user()->message))
{{ Auth::user()->message->name }}
@foreach(Auth::user()->message as $message)
{{ $message->name }}
@endforeach
@else
<p>No messages</p>
@endunless
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment