AppServiceProvider
public function boot(){
Validator::extend('count_books', function($attribute, $value, $parameters) {
$count = IssueBook::where('client_id', $value)->where('is_returned', false)->count()
return $count < 2;
});
}
StoreRequest
public function rules()
{
return [
'category_id' => 'exists:App\Category,id',
'client_id' => 'exists:App\Client,id|count_books',
'book_id' => 'exists:App\Book,id',
'days_issued' => 'nullable|string',
'is_returned' => 'nullable|boolean',
'return_date' => 'nullable|date',
];
}
return [
['full_name', 'contacts'],
['', 'type', 'name',],
];
$sheet->mergeCells('A1:B1');
$order = Post::with(['comments' => function ($q){
$q->where('user_id',Auth::id());
}])->whereHas('comments',function ($q){
$q->where('user_id',Auth::id());
})->get();
$schedule->command('my:command')->cron('*/7 07-22 * * *');
public function getPropAttribute(): string
{
return 'prop';
}
public function newInstance($attributes = [], $exists = false)
{
$model = parent::newInstance($attributes, $exists);
$model->setAppends($this->appends);
return $model;
}
(new \App\Models\User())->setAppends(['prop'])->newModelQuery()->get()->first()->toArray()
^ array:8 [
"id" => 2
"name" => "Алексеев Глеб Дмитриевич"
"email" => "fmarkov@example.com"
"email_verified_at" => "2022-06-16T02:18:03.000000Z"
"deleted_at" => null
"created_at" => "2022-06-16T02:18:03.000000Z"
"updated_at" => "2022-06-16T02:18:03.000000Z"
"prop" => "prop"
]
Route::delete('/project/{project}', [Controller::class, 'method'])->can('delete', 'project');
public function delete()
{
$result = parent::delete();
if($result){
$this->deleteImageProject($this->logo);
}
return $result;
}
public function destroy(Project $project)
{
$project->delete();
return response('', 204);
}
If a DELETE method is successfully applied, the origin server SHOULD
send a 202 (Accepted) status code if the action will likely succeed
but has not yet been enacted, a 204 (No Content) status code if the
action has been enacted and no further information is to be supplied,
or a 200 (OK) status code if the action has been enacted and the
response message includes a representation describing the status.
public function wantsJson()
{
$acceptable = $this->getAcceptableContentTypes();
return isset($acceptable[0]) && Str::contains(strtolower($acceptable[0]), ['/json', '+json']);
}
create sequence user_document_number;
CREATE TABLE documents(
id SERIAL,
number INT NOT NULL DEFAULT(nextval('user_document_number')),
text text,
PRIMARY KEY(id)
);
insert into documents(text) values('assaassa');
class Project extends Model{
............
public function getFullUrlAttribute(){
return функция которая делает из атрибута полной путь();
}
.........
}
public functions questions(){
$instance = $this->newRelatedInstance(Question::class);
$localKey = $this->getKeyName();
$query = $instance->newQuery()
->join('test_question', 'test_question.question_id', '=', 'questions.id')
->join('tests', 'tests.id', '=', 'test_question.test_id')
->join('lessons', 'lessons.id', '=', 'tests.lesson_id')
->join('modules', 'modules.id', '=', 'lessons.module_id')
return $this->newHasMany(
$query, $this, 'modules.course_id', $localKey
);
}