[PR]
×
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
$articles = Article::all();
return View::make('articles')->with('articles', $articles);
@foreach ($articles as $article)
<h2>{{{$article->title}}}</h2>
<p>posted by {{{$article->user->name}}}</p>
@endforeach
$articles = Article::with('user')->get();
class Article extends Eloquent {
public function writer()
{
return $this->belongsTo('Writer');
}
public function editor()
{
return $this->belongsTo('Editor');
}
public function company()
{
return $this->belongsTo('Company');
}
}
@foreach ($articles as $article)
<h2>{{{$article->title}}}</h2>
<p>筆者: {{{$article->writer->name}}}</p>
<p>編集者: {{{$article->editor->name}}}</p>
<p>提供社: {{{$article->company->name}}}</p>
@endforeach
$articles = Article::with('writer', 'editor', 'company')->get();
@foreach ($articles as $article)
<h2>{{{$article->title}}}</h2>
<p>編集者: {{{$article->editor->name}}}</p>
<p>提供社: {{{$article->editor->company->name}}}</p>
@endforeach
$articles = Article::with('editor.company')->get();
$articles = Article::with(['editor' => function ($query) {
$query->where('deleted', 0);
}])->get();
$articles = Article::all();
if ($user->role == 'writer') {
$articles->load('editor', 'company');
}
class User extends Eloquent {
public function articles()
{
return $this->hasMany('Article');
}
}
$articles = User::find(1)->articles;
$articles = User::find(1)->articles()->get();
public function address()
{
return $this->hasOne('Address');
}
$address = User::find(1)->address;
$address = User::find(1)->address()->first();
$zip_code = User::find(1)->address->zip_code;
$zip_code = User::find(1)->address()->first()->zip_code;
User::find(1)->articles->title;
$user = User::find(1);
foreach($user->articles as $article) {
$title = $article->title;
}
$user = User::find(1)->address();
↑こういう終わり方をするとデータではなくクエリが返ってきます。some_documents() ←これだとダメ
someDocuments() ←これだとOK
User::find(1)->some_documents ←これでもアクセスできる!
User::find(1)->someDocuments ←これは、もちろんOK
foreach($user->articles as $article) {
$title = $article->title;
}
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
$ brew update $ brew install mysql
$ mysql.server start
$ brew install composer
$ composer create-project laravel/laravel {directory} --prefer-dist
$ composer create-project laravel/laravel {directory} "~5.0.0" --prefer-dist
$ composer create-project laravel/laravel {directory} 4.2 --prefer-dist
$ mysql -uroot $ CREATE DATABASE {db_name};
$ php artisan serve
$ mysql.server stop