我有两个模型:Company和Representative。代表属于公司,公司有多名代表。
我还有两个相应的资源。
公司资源:
public function toArray($request)
{
return [
'id' => $this->id,
'title' => $this->title,
'representatives' => RepresentativeResource::collection($this->representatives)
];
}
Run Code Online (Sandbox Code Playgroud)
代表资源:
public function toArray($request)
{
return [
'id' => $this->id,
'company' => $this->company ? new CompanyResource($this->company) : null
];
}
Run Code Online (Sandbox Code Playgroud)
我想要实现的目标是,当我找到公司时,我想找到他们的代表。当我获得代表时,我想获得有关公司的信息。
发生的是无限循环:它们无限地相互包含。
那么,如何解决呢?
在我的 Laravel 5.6 应用程序中,我尝试将一个$id变量从我的路由传递到我的数据表的每一列。
我的代码:
public function getVendorslistChange($id){
try {
return Datatables::of($this->purchaseRepository->getVendorListData(),$id)
->addColumn('action', function ($vendor,$id) {
return \Form::open(['method' => 'POST', 'action' => ['PurchaseController@postChangeVendor',$id], 'class' => 'form']) . '
<input type="hidden" name="id" value="' . $vendor->id . '" />
<input type="submit" name="submit" value="Choose" class="btn center-block" />
' . \Form::close();
})
->make(true);
} catch (\Exception $e) {
return $this->redirectWithErrors($e);
}
}
Run Code Online (Sandbox Code Playgroud)
这部分$this->purchaseRepository->getVendorListData()将返回以下内容:
public function getVendorListData(){
$this->vendors = Vendor::Select(
array(
'vendors.id',
'vendors.company_name'
))
->where('vendors.company_id',return_company_id())
->where('status','Active')->get()
;
return $this->vendors;
}
Run Code Online (Sandbox Code Playgroud)
但是有错误说, …
我在 Laravel Forge 上使用 Laravel Nova 部署了我的 Laravel 应用程序。我用路径存储库安装了 Nova,我也有 Nova 用户。我替换了 NovaServiceProvider Gate 方法,如:
Gate::define(‘viewNova’, function ($user) {
return in_array($user->email, [
‘my@license.com’,
]);
});
Run Code Online (Sandbox Code Playgroud)
当我访问页面“/nova”时,有登录表单,但是当我尝试使用现有用户登录时,它会显示 403 错误页面并显示消息“对不起,您被禁止访问此页面”
我找到的唯一一篇文章是Medium 上的“设置 Laravel Nova 时的常见问题”。
问题#2:看起来像我的问题,但事实并非如此。我认为我的问题与许可证有关,否则,我尝试了所有方法。
我有一个单独的 Nova 许可证,我不必通过电子邮件向支持人员询问他们。
我有: Laravel5.7和 Nova:1.3.1
我的问题是:我应该购买专业版许可证吗?为什么?或者有什么问题?
我有一个控制器从我的数据库中获取用户日记的数组并将它们传递给我的视图:
<?php
public function readDiaries($hash)
{
$user = User::where('hash', $hash)->first();
$diaries = Diary::where('user_id', $user->id)->get();
return view('app.diary.readDiaries', ['diaries' => $diaries]);
}
Run Code Online (Sandbox Code Playgroud)
在我看来,我正在使用循环遍历日记@foreach.
<div id="diaries" class="card-columns">
@if (count($diaries) > 0)
@foreach ($diaries as $dairy)
{{ var_dump($diary) }}
@endforeach
@endif
</div>
Run Code Online (Sandbox Code Playgroud)
但我得到以下未定义的变量错误...
未定义的变量:日记(查看:C:\ xampp\htdocs\personal_projects\Active\diary_app\resources\views\app\diary\readDiaries.blade.php)
为什么我的$ diary变量在@foreach循环中未定义?
由于某种原因,我无法理解这个问题,尽管答案似乎就在我面前。
我有 3张桌子,rentals并且amenitiesamenities_rentals
便利设施包括空调、工作人员等。
有, .amenities_rentals 该表基本上是一个连接到 的参考表。rentail_idamenities_idrentalsamenities
在搜索中,用户可以通过勾选某些设施来缩小租金范围。到目前为止,它为我提供了所有至少有一个已勾选选项的租金。我需要将其范围缩小到仅拥有所有所选便利设施的出租房。这就是我所拥有的,这不仅没有正确地获取信息,而且我知道有更好的方法来做到这一点。
if($request->has('amenities'))
{
$rental_ids = AmenitiesRentals::select('rental_id')
->whereIn('amenities_id',$request->amenities)
->distinct()
->get();
$builder->whereIn('rentals.id', $rental_ids->toArray());
}
Run Code Online (Sandbox Code Playgroud)
构建器的其余部分工作正常。
早上好,尝试用Eloquent创建一个简单查询时遇到麻烦。
这是mi Colonia模型:
class Colonia extends Model
{
protected $table = 'catalogo_colonias';
public function city()
{
return $this->belongsTo('App\City', 'ciudades_id');
}
}
Run Code Online (Sandbox Code Playgroud)
如果我做。
$response = Colonia::find(1)->city;
Run Code Online (Sandbox Code Playgroud)
我正在得到答复,但我不想通过id查找,我正在尝试做出这样的事情。
$response = Colonia::where('codigo_postal', $codigo_postal)->city;
Run Code Online (Sandbox Code Playgroud)
但这给我一个错误。
未定义的属性:Illuminate \ Database \ Eloquent \ Builder :: $ city
如您所见,它已在上面声明,我想这是一个语法问题,希望对您有所帮助。
谢谢你,问候。
我想将数据插入我在 laravel 迁移中创建的模式中,但我找不到方法。
有人可以指导一下吗?
public function up()
{
DB::statement('CREATE SCHEMA IF NOT EXISTS reports');
Schema::create('reports.campaign_reports', function (Blueprint $table)
{
$table->bigIncrements('id');
$table->string('campaign')->nullable();
$table->string('currency')->nullable();
});
}
Run Code Online (Sandbox Code Playgroud)
这是我的模型:
class CampaignReport extends Model
{
// protected $connection = 'schema.reports';
protected $table = 'campaign_reports';
protected $fillable = [
'campaign',
'currency'
];
}
Run Code Online (Sandbox Code Playgroud)
这就是我节省的方式:
CampaignReport::create((array) $dataObject);
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
SQLSTATE[42P01]:未定义表:7错误:关系“campaign_reports”不存在第1行:插入“campaign_reports”(“campaign”,“currency”,...
我想在项目中命名表格,我有一个用于旅行服务的表格。
表格和模型的最佳命名方法是什么?camelCase,snake_case或PascalCase(上部camelCase)?
适用于桌子'tourServices'和模特'TourService'吗?
return response()->json([
'message' => 'No new orders!'
]);
Run Code Online (Sandbox Code Playgroud)
不幸的是,此响应不起作用?理想情况下,我想返回一个带有“消息”=>“没有新订单!”的 JSON 响应。状态码为 204 No Content。
我在控制器中有这 2 个包含文件...
use OhMyBrew\BasicShopifyAPI;
use GuzzleHttp\Client;
Run Code Online (Sandbox Code Playgroud)
这利用了来自vendor/laravel/framework/src/Illuminate/foundation/helpers.php 的这个内置帮助器
if (! function_exists('response')) {
/**
* Return a new response from the application.
*
* @param \Illuminate\View\View|string|array|null $content
* @param int $status
* @param array $headers
* @return \Illuminate\Http\Response|\Illuminate\Contracts\Routing\ResponseFactory
*/
function response($content = '', $status = 200, array $headers = [])
{
$factory = app(ResponseFactory::class);
if (func_num_args() === 0) {
return $factory;
}
return …Run Code Online (Sandbox Code Playgroud) 我想查询用户并按年龄范围对他们进行分组
这是我到目前为止所做的
User::applicant()->get()
->groupBy(function ($item) {
return Carbon::parse($item->dob)->age;
})
->map(function ($collection) {
return $collection->count();
});
Run Code Online (Sandbox Code Playgroud)
这是我从上面的查询中得到的
现在想按年龄范围获取集合和订单
18-24: 1,
25-35: 5,
36-45: 89,
46+ : 84
Run Code Online (Sandbox Code Playgroud) 这是我做的第一件事
php artisan make:auth
Run Code Online (Sandbox Code Playgroud)
结果:
Run Code Online (Sandbox Code Playgroud)Command "make:auth" is not defined. Did you mean one of these? make:channel make:command make:controller make:event make:exception make:factory make:job make:listener make:mail make:middleware make:migration make:model make:notification make:observer make:policy make:provider make:request make:resource make:rule make:seeder make:test
第二个:
php artisan ui vue --auth php artisan ui react --auth
我试过这个,这是结果
Run Code Online (Sandbox Code Playgroud)The "http://repo.packagist.org/p/provider-2015%24e84cdb7b9b7175f18a814c1783741a3ba6b021c4a78701285cc5639d0d1ee4e6.json"文件无法下载:无法打开流:HTTP 请求失败!
Run Code Online (Sandbox Code Playgroud)http://repo.packagist.org could not be fully loaded, package information was loaded from the local cache and may be out of date
我该怎么办?-谢谢