升级 Laravel 6 时出现错误
Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR) Class 'Illuminate\Support\Facades\Input' 未找到
源代码:
错误:
你能帮我修复我的代码吗?
如果我的main.php文件位于里面,/wp-content/plugins/myplugin/folder/folder/folder/
为什么包含urls.php,位于里面的文件/wp-content/uploads/folder/不能用于这个路径:
include_once("../../../../../uploads/folder/urls.php");
Run Code Online (Sandbox Code Playgroud)
仅当放置在与 main.php 相同的文件夹中并带有路径时才有效 ('urls.php');
当ModelNotFoundException发生时,我想返回一个 JSON 响应而不是默认的 404 错误页面。为此,我将以下代码写入app\Exceptions\Handler.php:
public function render($request, Exception $exception)
{
if ($exception instanceof ModelNotFoundException) {
return response()->json([
'error' => 'Resource not found'
], 404);
}
return parent::render($request, $exception);
}
Run Code Online (Sandbox Code Playgroud)
但是它不起作用。当ModelNotFoundException发生时,Laravel 只显示一个空白页面。我发现,即使是在宣告一个空的渲染功能Handler.php品牌Laravel上显示空白页ModelNotFoundException。
我该如何解决这个问题,以便它可以返回 JSON/执行覆盖渲染函数中的逻辑?
I've created Payment package for my laravel project
I want to make migration files inside migrations folder of my package. How can create it using artisan command? I want something like
php artisan make:migration packages/Payment/src/Database/add_orderId_to_cart_payment_table
Run Code Online (Sandbox Code Playgroud) 我正在使用Laravel 6.2.0,并且make:auth终端中未定义命令。有什么解决办法吗?注意Composer已经更新。
这是我的 html 代码。
<label><b>Phone Verified : </b></label>
<select class="form-control phone_verified">
<option value="">Select Option</option>
<option value="1">Yes ()</option>
<option value="0">No ()</option>
</select>
Run Code Online (Sandbox Code Playgroud)
我已经链接了 cdn 引导程序链接
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css" rel="stylesheet"/>
<style type="text/css">
select {
font-family: 'FontAwesome', 'open sans'
}
</style>
Run Code Online (Sandbox Code Playgroud)
在我的chrome 浏览器图标中完美运行。
但是在Firefox 中不起作用。
谁能告诉我我做错了什么?
检查 JSFiddle 链接:- https://jsfiddle.net/17j8pxqb/
当用户仅输入部分学生姓名时,我正在尝试获取学生记录。换句话说,检查当前学生姓名之一是否包含用户输入的字符串,如果是,则返回该记录。
我当前的代码,仅在用户输入全名后才返回记录:
public function getStudent($name) {
$std = Student::where('first_name', $name)->get();
return $std;
}
Run Code Online (Sandbox Code Playgroud)
谢谢
Laravel 版本 7.0
我有Team模型和User模型,team_has_users表格。
team_has_users表有team_id, user_id,role列。
一名用户可以属于一个具有不同角色的团队。
例如,一个用户可以作为客户和员工属于一个团队。
在Team模型中,我设置了这样的关系。
public function users(){
return $this->belongsToMany(User::class, 'team_has_user', 'team_id', 'user_id')
->withPivot('role');
}
Run Code Online (Sandbox Code Playgroud)
当我将用户加入团队时,效果很好。
$item->users()->attach($request->clients, ['role'=>'client']);
$item->users()->attach($request->employees, ['role'=>'employee']);
Run Code Online (Sandbox Code Playgroud)
但是,当我要同步它们时,我却做不到。
我尝试搜索并找到了类似的,syncwithoutDetaching但它似乎不适合我的情况。
team_has_users表可以是这样的。
team_id user_id role
1 1 client
1 1 employee
1 2 client
1 1 other
...
Run Code Online (Sandbox Code Playgroud)
谁能帮我?
谢谢你!
php laravel eloquent laravel-query-builder laravel-relations
我正在运行最新的 Laravel 6 并想要上传并解压 ZIP 文件。我尝试使用 Composer chumper/zipper - 但似乎它与 Laravel 6 不兼容。所以我尝试使用 PHP zipArchive。
我正在尝试的过程的代码是:
$docfileext1 = $request->file('czipfile')->getClientOriginalExtension();
$random_filename1 = substr(str_shuffle("abcdefghijklmnopqrstuvwxyz123"), -5);
$newfilename1 = $random_filename1.'.'.$docfileext1;
//First check this is a ZIP file
if ($docfileext1 <> 'zip') {
return back(); //->witherrors('this is not a ZIP file. Please select a zip file');
}
$request->file('czipfile')->move(
base_path() . '/storage/app/'.$oid.'/courses/'.$inscourse, $newfilename1
);
//Now unzip
$target_path = base_path() . '/storage/app/' .$oid. '/courses/'. $inscourse.'/'.$newfilename1;
$extract_path = base_path() . '/storage/app/' .$oid. '/courses/'. $inscourse.'/';
$zip = new ZipArchive(); …Run Code Online (Sandbox Code Playgroud) 在我的模型 ( Customer) 上,我有一个必需的参数:$contactId.
在执行时,Customer::create(['contactId' => $contactId])我收到以下错误:
"message": "SQLSTATE[HY000]: 一般错误: 1364 字段 'contactId' 没有默认值 (SQL: insert into
customers(updated_at,created_at) values (2019-12-10 12:33:46, 2019-12- 10 12:33:46))"
在插入语句中找不到 contactId 字段。的值contactId设置为4,通过一个 对应于数据库中的正确值FK。
Customer表的迁移:
`Schema::create('customers', function (Blueprint $table) {
$table->bigIncrements('id');
$table->timestamp('created_at')->default(DB::raw('CURRENT_TIMESTAMP'));
$table->timestamp('updated_at')->default(DB::raw('CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP'));
$table->bigInteger('contactId')->unsigned();
$table->foreign('contactId', 'FK_customer_contactId_contact_id')
->references('id')
->on('contacts');
});`
Run Code Online (Sandbox Code Playgroud)
是什么阻止Eloquent了在这里创建正确的插入语句?我已经三次检查了contactId整个流程和数据库中的拼写。
当我手动将一行插入到 中时customers,检索数据和contact-relation没有问题。
谢谢你的时间!
我参考了一些在线参考资料以了解如何处理 laravel 中的 With 方法,但仍然不明白。 Laravel with():这个方法有什么作用?
这里有一些我不明白的代码,我可以知道 a、b、c、d、e、f 指的是什么吗?
$example = Test::with('a', 'b', 'c',
'd', 'e', 'f');
Run Code Online (Sandbox Code Playgroud) 我刚刚安装了 Laravel 6.0.2。然后我使用以下命令创建了身份验证。
composer require laravel/ui
php artisan ui:auth
Run Code Online (Sandbox Code Playgroud)
现在,我运行登录页面,它显示如下。
现在我正在设置Layouts.php文件。
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
<script src="{{ asset('js/app.js') }}" defer></script>
Run Code Online (Sandbox Code Playgroud)
我也试过这个。
<link href="{{ asset('public/css/app.css') }}" rel="stylesheet">
<script src="{{ asset('public/js/app.js') }}" defer></script>
Run Code Online (Sandbox Code Playgroud)
在 Laravel 6 之前,CSS 和 JS 的文件夹存在于 public 文件夹中,但现在我找不到那个文件夹。谁能告诉我{{ asset('css/app.css') }}这个asset在 Laravel 6 中的位置是什么?