$data = HistoryWeightRecord::get();
$date = [];
foreach ($data as $allDate) {
$date[] = Carbon::parse($allDate->datetime)->format('Y-m-d');
}
$uniqueDate = collect($date)->unique();
$uniqueEquipment = $data->unique('equipment_id');
$sumArr = [];
foreach ($uniqueEquipment as $eqId) {
foreach ($uniqueDate as $day) {
$sum = HistoryWeightRecord::whereDate('datetime', $day)->where('equipment_id', $eqId->equipment_id)->sum('mass');
$sumArr[$eqId->equipment_id][$day] = $sum;
};
}
return $sumArr;
public function handle(Request $request, Closure $next)
{
$routeName = $request->route()->getAction()['as'];
$routeDescription = [
post.index => 'Просмотр списка постов',
post.create => 'Вызвал форму для создания поста',
post.store => 'Создал пост',
];
if (array_key_exists($routeName, $routeDescription)) {
$a = $routs[$routeName];
UserLog::create([
'date' => '2021-08-25',
'user_id' => 2,
'action' => $a,
]);
}
return $next($request);
}
public function destroy(Request $request)
{
$idle = Idle::find($request->get('id'));
if ($idle !== null) {
$idle->delete();
return $this->responseRepository->Response($idle, true, 'Запись с таким id удалена');
}
return $this->responseRepository->Response('Запись с таким id не обнаружена');
}
public static function Response($message = "Ошибка", $data = null, $status = false)
{
return response()->json([
'status' => $status,
'message' => $message,
'data' => $data,
]);
}
public function index(Request $request)
{
$limit = $request->get('limit');
$tags = $request->get('tags');
$array_tag = explode(",", $tags);
$employes = Employe::query()
->when($array_tag, function($q) use ($array_tag){
$q->whereHas('tags', function($q) use ($array_tag) {
$q->whereIn('tag_id', $array_tag);
});
})->paginate($limit);
return $employes;
}
<form action="{{ (empty($cats) ? route('category.store') : route('category.update', ['id'=>$cats->id])) }}" method="post" enctype="multipart/form-data">
@csrf
@if (isset($cats))
@method('PATCH')
@endif
<div class="form-group">
<label for="cat_id">Категория</label>
{{$cats->tite ?? ''}}
</div>
<div class="form-group">
<input name="category[title]" type="text" class="form-control" required value="{{ $cats->title ?? ''}}">
</div>
<input type="submit" value="Создать" class="btn btn-outline-success">
</form>
Schema::create('categories_roles', function (Blueprint $table) {
$table->bigInteger('category_id')->unsigned();
$table->bigInteger('role_id')->unsigned();
$table->foreign('category_id')->references('id')->on('categories')->onDelete('cascade');
$table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade');
$table->primary(['category_id', 'role_id']);
$table->timestamps();
});