我有一个自定义CMS,我在Laravel中从头开始编写,并希望env
在用户设置后从控制器设置值,即数据库详细信息,邮件程序详细信息,常规配置等,并希望为用户提供在运行时更改它们的灵活性我正在制作的GUI.
所以我的问题是如何.env
从控制器中将我从用户收到的值写入文件.
并且.env
随时随地构建文件是一个好主意还是有其他方法吗?
提前致谢.
我正在使用 RESTful 控制器并且传递变量(使用表单)在这里工作得很好。
现在出于某种原因,我需要使用简单的链接,创建action()
和专用的@create
行动路线。
我的视图创建了几个具有不同参数的类似链接:
<a href="{!! action('\App\Http\Controllers\Admin\Franch\Category\SubCategoryController@create', array('mainCategoryName' => $mainCategoryName)) !!}">
Run Code Online (Sandbox Code Playgroud)
它有效,因为我可以在 URL 中看到:
/create?mainCategoryName=some_sample_name
但是路由不会将变量传递给 @create 操作,或者控制器由于某种原因没有收到它:
Route::get('admin/franch/sub_categories/create', ['uses' => 'Admin\Franch\Category\SubCategoryController@create');
Run Code Online (Sandbox Code Playgroud)
我想知道如何使用 GET 和 POST 方法将变量从视图传递到特定控制器?
这是我的@create 控制器:
public function create($mainCategoryName = false)
{
dd($mainCategoryName);
....
Run Code Online (Sandbox Code Playgroud)
这总是给false
.
我有两个模型,一个是要约(用于要约表),另一个是品牌(用于品牌表)。这些模型之间存在“多对多”关系。
我有一个表offer_brands,它映射了这两个表之间的关系。在此表中,我具有offer_id列(可将此表链接到商品表)和brand列(可将此表链接到brands表),brands表中的usind brand_name列。
在品牌模型中,我想要一个可以返回所有报价的关系。
我知道我可以做到
public function offers()
{
return $this->belongsToMany(Offer::class, 'offer_brands', 'offer_id', 'brand_id'); // But don't have brand_id column insted I have brand column that contains brand names
}
Run Code Online (Sandbox Code Playgroud)
另外,我尝试了
public function offers()
{
return $this->belongsToMany(Offer::class, 'offer_brands', 'offer_id', 'brand'); // But Eloquent compare this column with id column of brands table.
}
Run Code Online (Sandbox Code Playgroud) 有时我们在哪里使用这样的场景Laravel
,如下所示:
if (!empty($request->input('user_name'))) {
$where[] = ['user_name', 'like', "%" . $request->input('user_name') . "%"];
}
if (!empty($request->input('group_id'))) {
$where[] = ['group_id', $request->input('group_id') ];
}
if (!empty($request->input('email'))) {
$where[] = ['email', 'like', "%" . $request->input('email') . "%"];
}
if (!empty($request->input('mobile'))) {
$where[] = ['mobile', 'like', "%" . $request->input('mobile') . "%"];
}
$users = User::where($where)->get();
Run Code Online (Sandbox Code Playgroud)
但它太丑了,但我只是想用这个User::search($request->only(['user_name', 'email', 'mobile']));
,也许我们必须为输入名称的键名设计一些规则,你对这个条件有一些好主意吗?谢谢.
我有一个这样的集合:
Collection {#750 ?
#items: array:18 [?
18 => User {#691 ?}
19 => User {#696 ?}
20 => User {#701 ?}
]
}
Run Code Online (Sandbox Code Playgroud)
18、19、20 应该不同的地方
我试着打电话
$collection->get(0);
$collection->get(1);
$collection->get(2);
Run Code Online (Sandbox Code Playgroud)
但显然,它不起作用
我找到了一种使用 shift 的解决方法,它返回第一个元素并将其从集合中删除,
$el1 = $collection->shift();
$el2 = $collection->shift();
$el3 = $collection->shift();
Run Code Online (Sandbox Code Playgroud)
但在这种情况下,我的原始收藏被破坏了。
知道我应该怎么做吗?
我试图获得刀片中的小时,分钟和秒,通常我像下面这样使用
{{$calllog['delivery_date']}}
Run Code Online (Sandbox Code Playgroud)
但现在我的要求是获取小时,分钟和秒。这是我试图得到的
$calllog['delivery_date']->todatestring()}}
Run Code Online (Sandbox Code Playgroud)
是的,我想我误用了此功能,有人可以帮我吗?我是Laravel新手。任何帮助将不胜感激。
I am using Laravel schedule to run cron jobs.
In my crontab I have added (with correct path to my project):
* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1
Run Code Online (Sandbox Code Playgroud)
Now my App\Console\Kernel.php looks like:
protected function schedule(Schedule $schedule)
{
$schedule->command('investments:calculate_interests')->everyMinute();
$schedule->call('\App\Http\Controllers\UsersController@testEvent')->everyMinute();
}
Run Code Online (Sandbox Code Playgroud)
Using it like that I successfully run jobs every minute. But how I can change it to run them on every 10 or 20 or 30 seconds?
我想获得具有相同ID的最新记录.例如我有桌子
ID | Created_at
1 |2016-04-26
1 |2016-04-20
1 |2016-04-18
2 |2016-04-27
2 |2016-04-19
Run Code Online (Sandbox Code Playgroud)
我想得到这样的结果
ID | Created_at
1 |2016-04-26
2 |2016-04-27
Run Code Online (Sandbox Code Playgroud)
我怎么在Laravel做这个?我只能按降序排序记录.不知道如何挑选每个ID的最新记录.谢谢.
我想了解Laravel中的模型和表约定。
我现在有表用户和user_address,我不想使用
受保护的$ table =“ user_address”
属性。请在模型或表格中建议我正确的约定。
我刚刚 使用laravel和vue-router 创建了我的投资组合网站http://ashishpatel.info,现在我想在aws ec2-instance上托管它,我们可以通过两种方式完成它.
1 - 使用php artisan,
php artisan serve --host=0.0.0.0 --port=80
Run Code Online (Sandbox Code Playgroud)
2 - 使用apache/nginx并在apache2.conf等中做一些更改
我想知道哪种方法可以用于处理更多流量的生产?
我目前有一个 1:1 的关系,我需要它是一对多的关系。这样Job Details
可以有多个结果 1 Job Search
。
求职
public function up()
{
Schema::create('job_searches', function (Blueprint $table) {
$table->increments('id');
});
}
Run Code Online (Sandbox Code Playgroud)
工作详情
public function up()
{
Schema::create('job_details', function (Blueprint $table) {
$table->integer('job_details_id',11);
$table->foreign('job_details_id')->references('id')->on('job_searches');
});
}
Run Code Online (Sandbox Code Playgroud)
我得到的当前输出是:
Job_Search_Id
1
Job_Detail_Id
1
Run Code Online (Sandbox Code Playgroud)
将另一个结果添加到job details
我得到:
Illuminate\Database\QueryException 带有消息“SQLSTATE[23503]:外键违规:7 错误:插入或更新表“job_details”违反外键约束“job_details_job_details_id_foreign”
我也已经说明了我的模型中的关系
求职模式
class JobSearches extends Model
{
protected $primaryKey = 'id';
public function job_details(){
return $this->belongsToMany('App\job_details');
}
}
Run Code Online (Sandbox Code Playgroud)
工作详情模型
class JobDetails extends Model
{
protected $primaryKey = 'job_details_id';
public function job_search(){ …
Run Code Online (Sandbox Code Playgroud) 我有一个分页的记录列表,用户可以编辑一条记录;这激发了我的更新方法;
public function update($id, Request $request)
{
$questionUpdate=$request->all();
$question = Question::find($id);
$question->update($questionUpdate);
return redirect('questions');
}
Run Code Online (Sandbox Code Playgroud)
但它会丢失其上的页面(用于分页)。
如何使其重定向到正确的路由/页面?
我在删除 HTML 标签时遇到问题。好吧,我从数据库中获取字符串
$desc = "<p>Test 1</p>";
Run Code Online (Sandbox Code Playgroud)
当我用 htmlspecialchars 和其他过滤变量时,我有 < 和其他东西。是否有任何函数可以删除标签并将变量设置为
$desc = "Test 1";
Run Code Online (Sandbox Code Playgroud) laravel ×13
php ×6
eloquent ×2
laravel-5 ×2
apache ×1
collections ×1
controller ×1
datetime ×1
migration ×1
models ×1
mysql ×1
nginx ×1
pagination ×1
postgresql ×1
view ×1
vue.js ×1