$result = MyModel::with('users:email')->get()->map(function ($item) {
$item['users'] = $item['users'][0]['email'];
return $item;
});
array:1 [▼
0 => array:5 [▼
"id" => 1
"user_id" => "222"
"mymodel" => "success"
"created_at" => "2023-07-26T15:48:44.000000Z"
"updated_at" => "2023-07-26T15:48:44.000000Z"
"users" => "e@test.com"
]
]
select * from tbl
where id_ref = 99 and delete = 0
order by id_carrier desc
limit 1;
multipart
contents
$csv_data = 'xxxx;yyy;zzz';
$client->request('POST', '/post', [
'multipart' => [
[
'name' => 'mycsv',
'contents' => $csv_data,
'filename' => 'custom_filename.csv'
],
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.com/add/?token=TOKEN&id=ID8&value=100&name=TEST');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, ['file' => new CurlFile($_SERVER['DOCUMENT_ROOT'] . '/upload/test.txt')]);
$headers = array();
$headers[] = 'Content-Type: multipart/form-data; boundary=---011000010111000001101001';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
echo $result;
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
\DB::query()
->from((new Name())->getTable(), 't')
->where('created_at', '=', function ($q) {
$q
->from((new Name())->getTable(), 't2')
->selectRaw('MAX(t2.created_at)')
->whereRaw('t2.name = t.name')
->whereRaw('t2.marker = t.marker');
})
->get();
...
$perms = auth()->user()->permissions;
$records= array();
foreach($perms as $perm){
if (strpos($perm->slug, 'record-') !== false) {
$records[] = str_replace('record-','',$perm->slug);
}
}
$table = Record::query();
$table->whereIn('name_record', $records);
return Datatables::eloquent($table)
...
Route::get('/page', [PageController::class, 'index'])->name('page')->middleware('role:admin,manager');
...
public function handle($request, Closure $next, $role1, $role2)
{
//Используем уже здесь $role1, $role2
...
Route::get('/page', [PageController::class, 'index'])->name('page')->middleware('role:admin|manager');
...
public function handle($request, Closure $next, $role)
{
if (!is_array($role)) {
$roles = explode('|', $role);
}
...
public function getFiles()
{
$path = public_path('images');
$files = File::files($path);
return $files;
}
$.get( "{!! route('your_url') !!}", function( data ) {
console.log(data);
});