阅读 L aravel 11 文档时,我看到会话存储在 中storage/framework/session
,但是根据CIS 基准指南,这有些不安全,我们的项目必须遵循其中一些指南。
Laravel 是否允许我将会话目录更改为类似的目录/tmp
?
阅读 L aravel 11 文档时,我看到会话存储在 中storage/framework/session
,但是根据CIS 基准指南,这有些不安全,我们的项目必须遵循其中一些指南。
Laravel 是否允许我将会话目录更改为类似的目录/tmp
?
当我访问my.site/api/genre/slug-name时
在route/api.php
:
Route::prefix('genre')->group(function () {
Route::get('/{slug}', [FilmController::class,'getFilmByGenre'])->name('api_genre_film');
});
在getFilmByGenre
:
public function getFilmByGenre(Request $request, string $slug)
{
dd($slug, $request->slug, $request->get("slug")); // "slug-name" - "slug-name" - null
}
$slug
谁能向我解释一下使用,$request->slug
和时的区别$request->get("slug")
吗?
我正在使用 laravel 10.x。感谢您的帮助!
我正在使用 Laravel 8 制定饮食计划。
数据库看起来像这样:
食谱 | 类别 | 卡路里 |
---|---|---|
苹果派 | 零食 | 第289章 |
香蕉派 | 零食 | 第386章 |
番茄意大利面 | 午餐 | 第712章 |
鸡肉沙拉 | 午餐 | 第756章 |
蔬菜汤 | 晚餐 | 410 |
鱼配土豆 | 晚餐 | 第652章 |
我想根据每日卡路里显示当天的膳食。
例如,如果我每天的热量是1500kcal,我想要当天的3份食谱(午餐/晚餐/零食),其总热量不超过1500kcal。
我知道我可以显示不超过一定卡路里数的膳食:
$recipes = Recipe::where('category', 'snacks')
->where('calories', '<', '300')
->get()
;
但是如何从不同类别中随机获得3种不超过1500kcal的不同膳食呢?
我希望我已经说清楚了
这里我使用 Laravel 11 并用 vue3 代替blade。所以我在惯性Js的帮助下在Laravel框架内使用vue3
控制器
public function addInfo(Request $request){
$validatedData = $request->validate([
'title' => 'required|string|max:25',
'message' => 'required|string',
'days' => 'required|integer|min:1',
]);
$count= Information::all()->count();
if($count >= 5){
$error = ([
'message'=> 'intonation not allowed more then 5 please delete old one',
'status' => false,
]);
return response()->json($error);
}
$new_info = new Information();
$new_info->title = $request->title;
$new_info->content = $request->message;
$new_info->days = $request->days;
$new_info->links = json_encode($request->links);
$new_info->save();
}
VUE3
const form = useForm({
title: '',
message: '',
days: '',
links:[],
});
form.post(route('info.add'), {
preserveScroll: true,
onSuccess: () =>{
form.reset();
lastInput.forEach(lastInput => {
lastInput.remove();
});
console.log(error);
showAlert('success', 'Info added Successfully');
},
onError: () => {
}
});
我想知道我怎样才能得到 return response()->json($error)
;在 vue 或任何其他进程中显示onError: ()
以使用 laravel web 路由显示错误
Laravel 中的这段代码我想将其用作 API 来向每个访问我的应用程序的人显示它。我想在他登录时获取用户 ID
public function show($displayType)
{
try {
$data = houses::where('displayType', $displayType)->paginate(5);
$user = auth()->user(); // Get the authenticated user
$userId = $user ? $user->id : null; // Check if user is authenticated and get the user ID
return response()->json([
'status' => true,
'message' => 'You have successfully retrieved data',
'data' => $data,
'user_id' => $userId, // Include the user ID in the response
]);
} catch (\Throwable $th) {
return response()->json([
'status' => false,
'message' => $th->getMessage(),
], 500);
}
}
我想检查访问我网站的人是否已登录
但问题是当我发送令牌时返回用户 id null 这就是如何使用我的路由请求。// 这是我的路线,我在中间件检查中使用它
Route::get('houses/{displayType}',[housesController::class, 'show']);
Route::middleware('auth:api')->group(function () {})
我正在寻求实现一个搜索功能,该功能可以选择包括供用户搜索的各个字段。
到目前为止我的代码:
$categories = $request->input('category'); // array(int)
$textSearch = $request->input('text'); // string
$query = Product::query();
if(!is_null($categories)){
//$query->selectSub();
foreach($categories as $catId){
$category = ShopCategory::find($catId);
$query = $query->whereBelongsTo($category);//TODO
}
}
if(!is_null($textSearch)){
$query = $query->whereAny([
'name',
'description',
'shortDescription',
],
'like', '%'.$textSearch.'%');
}
$searchResults = $query->paginate(36);
我的目标是达到相当于以下内容的 SQL 语句:
SELECT * FROM products WHERE (shop_category_id = ? OR shop_category_id = ?) AND (/* text search LIKE */)
但到目前为止,我最终得到的更多的是:
SELECT * FROM products WHERE shop_category_id = ? AND shop_category_id = ? AND (/* text search LIKE */)
其中每个类别 id 都AND
作为整体查询的一部分进行编辑,而不是OR
在组中进行编辑。
我知道or*()
查询方法,但不清楚如何正确地将它们分组以获得所需的效果,而不是仅仅OR
将它们与文本搜索一起使用。
编辑:根据已接受的答案,我得出了以下结论:
$mainQuery->where(function($query) use ($categories) {
foreach ($categories as $catId) {
$category = ShopCategory::find($catId);
$query->orWhereBelongsTo($category);
}
});
我的程序是这样的 =
$listreq2 = OutboundRequest::with('outboundmaterialrequest')
->whereIn('id', $outboundIds)
->whereHas('outboundmaterialrequest', function ($query) use ($ids) {
$query->whereIn('id', $ids);
})->get();
为什么我的数据过滤器->whereHas('outbound material request', function ($query) use ($ids) {
不起作用 $ids 的内容例如 = 2,3
但所有出库材料请求数据均出现
在“npm run dev”上运行时预览页面看起来不错。然后,我运行“npm run build”,命令行中没有错误,一切看起来都很好。但是,当我预览页面时,它现在显示此
错误:数组到字符串的转换
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
@vite(['resources/scss/app.scss'], ['resources/js/app.js']) // error here
</head>
<body>
</body>
</html>
我正在将 statamic 从版本 3.3 升级到 4.5,并且遇到 URL 未合并子条目的问题。对于此包的设置,我们还使用静态雄辩驱动程序来使用数据库,而不是文件。
父条目以前有“home”的副词,而子问题有“test”的副词。该特定条目的数据库列“uri”的 uri 为“/home/test”,但该 url 不可访问。仅将其更改为扁平结构,例如“/test”即可。
此外,当使用仪表板手动更新子问题时,uri 也会自动更新到此平面版本。
有什么方法可以更改配置/更改子条目,以便这些条目可以保留其完整路径?
需要将计算属性附加到模型中:
class Field extends Model {
//...
protected $appends = ['typename'];
//...
public function getTypenameAttribute(): string {
return $this->type->name;
}
}
模型转储向我显示以下内容:
{
"id": "9bc5b05b-46cf-470d-a848-cdb60aec2213",
"name": "Показание термометра",
"default": true,
"twin_id": "9bc5b05b-3df3-4efd-8ce0-7a30be87af72",
"type_id": "9bc3cea3-47e6-4ef2-a78f-347d51abbe3d",
"created_at": "2024-04-10T07:21:36.000000Z",
"updated_at": "2024-04-10T07:21:36.000000Z",
"deleted_at": null,
"origin": "thermo",
"typename": "Целочисленное без знака",
"type": {
"id": "9bc3cea3-47e6-4ef2-a78f-347d51abbe3d",
"name": "Целочисленное без знака",
"influx_type": "uint",
"created_at": "2024-04-09T08:54:37.000000Z",
"updated_at": "2024-04-09T08:54:37.000000Z",
"deleted_at": null
}
}
typename
计算好了。但我不想包含嵌套type
对象。我的模型类不包含任何$with
,所以这个对象完全出乎意料。
如何从转储中排除这个嵌套对象?