{{ $title }}
{!! $title !!}
<?php echo e($title); ?>
@foreach ($services as $service)
<div class="row">
<div class="col-md-9">
{{ Form::text("services_item[]", $service->service_item, array('class' => 'form-control input-services', 'placeholder' => 'Введите название услуги')) }}
</div>
<div class="col-md-1">
<a href="/service_{{ $service->id }}/delete" class="btn btn-danger">Удалить</a>
</div>
</div>
@endforeach
"services_item[{$service->something}]"
id (int), user_id (int), comment (text), commentable_type (string, index), commentable_id (int, index)
class Comment extends Model
{
protected $table = 'comments';
public function commentable()
{
return $this->morphTo();
}
}
public function comments(){
return $this->morphMany('App\Comment', 'commentable');
}
->whereRaw("`name` = '{$request->foo}'");
Таблица product:
id, name, purchase_id, category_id
Таблица category:
id, name
Таблица purchase:
id, total
public function purchase(){
$this->hasMany('Purchase');
}
$purchases = Product::with('purchase')->whereHas('category', function($query){
$query->where('id', 1);
})->get()->lists('purchase');
DB::table('orders')
->select('source','type', 'price')
->whereBetween('created_at', array(Carbon::yesterday()->startOfDay(), Carbon::yesterday()->endOfDay()))
->get()->groupBy('source');
<table>
<tr>
<th>Source</th>
<th>Нал</th>
<th>Безнал</th>
</tr>
@foreach($rows as $source => $row)
<tr>
<td>{{ $source }}</td>
<td>{{ $row->where('type', 'нал')->sum('price') }}</td>
<td>{{ $row->where('type', 'безнал')->sum('price') }}</td>
</tr>
@endforeach
</table>
echo \App\Models\User::find(Auth::user()->id)->GetUserPhoto->name;
Auth::user()
и так содержит объект модели User. Зачем получать id из модели, и снова делать запрос к базе?{{ Auth::user()->GetUserPhoto->name }}
public function userPhoto() {
return $this->hasOne('App\Models\Photo_user'); // Советую называть модели как нормальные люди. UserPhoto - как вариант. Забудьте нижнее подчеркивание, весь Laravel - это CamelCase.
}
public function getUserPhotoAttribute(){
if ( ! array_key_exists('userPhoto', $this->relations))
$this->load('userPhoto');
$related = $this->getRelation('userPhoto')->first();
return ($related) ? $related->name : false; // выводим userPhoto->first()->name
}
{{ Auth::user()->userPhoto }}
Post::with('commentsCount')->get();
public function commentsCount()
{
return $this->comments()
->selectRaw('count(id) as aggregate')
->groupBy('id');
}
public function getCommentsCountAttribute()
{
if ( ! array_key_exists('commentsCount', $this->relations))
$this->load('commentsCount');
$related = $this->getRelation('commentsCount')->first();
return ($related) ? (int) $related->aggregate : 0;
}