我正在尝试使用 Laravel Sail 在本地处理现有项目。我不断收到 1049 未知数据库错误。我尝试过以下方法:
sail php artisan config:clear
sail php artisan config:cache
Run Code Online (Sandbox Code Playgroud)
我还尝试将 mysql 替换为使用 127.1.1.0 的主机,例如 .env.example 文件,但没有成功。
我也尝试过重建容器,但似乎没有解决问题。
这是我的 .env 文件(当我尝试使用 root 以外的用户时,我收到 1045 错误,指出访问被拒绝,想知道这些是否相关):
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=
Run Code Online (Sandbox Code Playgroud)
这是我的 docker-compose.yml 文件:
mysql:
image: 'mysql:8.0'
ports:
- '${FORWARD_DB_PORT:-3306}:3306'
environment:
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
MYSQL_DATABASE: '${DB_DATABASE}'
MYSQL_USER: '${DB_USERNAME}'
MYSQL_PASSWORD: '${DB_PASSWORD}'
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
volumes:
- 'sailmysql:/var/lib/mysql'
networks:
- sail
Run Code Online (Sandbox Code Playgroud)
数据库配置:
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' …Run Code Online (Sandbox Code Playgroud) 我正在使用 laravel 8。我想通过从一个表选择到另一个表来插入多行。我正在使用 DB::statement() 但现在想使用 eloquent 来做到这一点。这是我的示例代码:
DB::statement("insert into bank_information (user_id, bank_id, account_name,account_number)
select applicant_id,bank_id,account_name,account_number from applicant_bank_information
where erec_applicant_bank_information.applicant_id =".$applicant_id);
Run Code Online (Sandbox Code Playgroud)
我怎样才能使用单个雄辩命令来做到这一点?另外,laravel 中还有其他更智能/更快的方法吗?
当我尝试从表单注册某些内容时,出现此错误。我将发布代码,然后解释情况
查看代码
@extends('layouts.app')
@section('content')
<div class="container">
<h1>Crear Especialidad</h1>
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">{{ __('Register') }}</div>
<div class="card-body">
<form method="POST" action="{{ route('especialidades.create') }}">
@csrf
<div class="form-group row">
<label for="nombre" class="col-md-4 col-form-label text-md-right">{{ __('Nombre') }}</label>
<div class="col-md-6">
<input id="nombre" type="text" class="form-control @error('nombre') is-invalid @enderror" name="nombre" value="{{ old('nombre') }}" required autocomplete="nombre" autofocus>
@error('nombre')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
</div>
<div class="form-group row mb-0">
<div class="col-md-6 offset-md-4">
<button type="submit" class="btn btn-primary">
{{ __('Registrar') }}
</button>
</div> …Run Code Online (Sandbox Code Playgroud) 我最近更新了我的 laravel 8,似乎 Carbon 或日期请求无法正常工作我在保存带有日期时间的记录时收到以下错误
exception: "Error"
file: "/../vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php"
line: 848
message: "Call to undefined method DateTime::set()"
Run Code Online (Sandbox Code Playgroud)
控制器
$startDate = $request->start_date_time;
$events->start_date_time = Carbon::parse($startDate);
Run Code Online (Sandbox Code Playgroud)
解析字符串: 2021-07-14T07:43:27.498Z
版本
PHP 7.4.21、Laravel 8
我正在尝试在表单注册器上上传图像,但是当我提交此表单时,我收到此错误“图像必须是图像。”。我已经更改了模型以接受所有图像扩展名,并尝试在我的表单上添加“enctype =“multipart/form-data””,但它不起作用。
\n我该如何解决这个问题?我需要上传这张图片。
<?php\n\nnamespace App\\Models;\n\nuse Illuminate\\Database\\Eloquent\\Factories\\HasFactory;\nuse Illuminate\\Database\\Eloquent\\Model;\nuse Illuminate\\Foundation\\Auth\\User;\nuse Illuminate\\Foundation\\Livros;\n\nclass Livro extends Model\n{\n use HasFactory;\n \n /**\n * The attributes that are mass assignable.\n *\n * @var array\n */\n protected $fillable = [\n 'livro',\n 'users_id',\n 'namel',\n 'autor',\n 'editora',\n 'categoria',\n 'classifica\xc3\xa7\xc3\xa3o',\n 'descricao',\n 'image'=>'required|image|mimes:jpeg,jpg,png,bmp,gif,svg',\n\n ];\n\n}\nRun Code Online (Sandbox Code Playgroud)\n控制器
\nprotected function validator(Request $request)\n{\n return Validator::make($request, [\n 'namel' => ['required', 'string', 'max:200'],\n 'autor' => ['required', 'string', 'email', 'max:200'],\n 'editora' => ['required', 'string', 'max:50'],\n 'categoria'=> ['required', 'string', 'min:50'],\n 'classifica\xc3\xa7\xc3\xa3o'=> ['required', 'string', 'min:1','max:2'],\n 'descricao'=> ['required', 'string', …Run Code Online (Sandbox Code Playgroud) 我有一个提交大量图像的表单,假设有 5 张图像。我将它们命名为img1、img2...、img5。现在我正在一一验证这些字段。
我的验证码
$rules = [
'image1' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:3072',
'image2' => 'image|mimes:jpeg,png,jpg,gif,svg|max:3072',
'image3' => 'image|mimes:jpeg,png,jpg,gif,svg|max:3072',
'image4' => 'image|mimes:jpeg,png,jpg,gif,svg|max:3072',
'image5' => 'image|mimes:jpeg,png,jpg,gif,svg|max:3072',
];
$msg = [
'image1.required' => 'Image is required',
'image1.image' => 'Please upload an Image for Image ',
'image1.mimes' => 'Image type should be jpeg or jpg or png or gif or svg',
'image1.max' => 'Image size should be less than or equal 3MB',
'image2.image' => 'Please upload an Image for Image ',
'image2.mimes' => 'Image type should …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 JetStream + 惯性将vuetify 3安装到 Laravel 8。我成功安装了 Vuetify 插件,但我不确定如何将该插件包含到 app.js 中。
这是我的 app.js
require('./bootstrap');
import { createApp, h } from 'vue';
import { createInertiaApp } from '@inertiajs/inertia-vue3';
import { InertiaProgress } from '@inertiajs/progress';
import 'vuetify/styles';
import { createVuetify } from 'vuetify';
const appName = window.document.getElementsByTagName('title')[0]?.innerText || 'Laravel';
const vuetify = createVuetify();
createInertiaApp({
title: (title) => `${title} - ${appName}`,
resolve: (name) => require(`./Pages/${name}.vue`),
setup({ el, app, props, plugin }) {
return createApp({ render: () => h(app, props) })
.use(plugin) …Run Code Online (Sandbox Code Playgroud)我正在 laravel 中创建迁移,有时我需要在数据库中创建自定义外键名称。我已经搜索过这个解决方案,但没有与我的问题类似的内容。
\n我想添加列names包含birth_city_id、birth_state_id 和birth_country_id 的表添加列。除此之外,我还想添加 Death_city_id、death_state_id、death_county_id。
错误:
\nMigrating: 2021_11_21_130238_create_names_table\n\n Illuminate\\Database\\QueryException \n\n SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \')\' at line 1 (SQL: alter table `names` add constraint `birth_city_id` foreign key (`city_id`) references `cities` ())\n\n at vendor/laravel/framework/src/Illuminate/Database/Connection.php:703\n 699\xe2\x96\x95 // If an exception occurs when attempting to run a query, …Run Code Online (Sandbox Code Playgroud) 我刚刚安装了 Laravel 8,在这个版本中,我必须像这样输入我的路线:
Route::get('/admin/panel', [App\Http\Controllers\Admin\PanelController::class, 'index']);
Run Code Online (Sandbox Code Playgroud)
但我习惯了 Laravel 5 的路线,如下所示:
Route::namespace('Admin')->prefix('admin')->group(function () {
Route::get('/panel', 'Admin/PanelController@index');
});
Run Code Online (Sandbox Code Playgroud)
那么如何在 Laravel 8 版本中使用 Laravel 5 路由呢?
-----> Building on the Heroku-20 stack
-----> Using buildpack: heroku/php
-----> PHP app detected
-----> Bootstrapping...
-----> Installing platform packages...
! ERROR: Failed to install system packages!
!
! Your platform requirements (for runtimes and extensions) could
! not be resolved to an installable set of dependencies, or a
! platform package repository was unreachable.
!
! This usually means that you (or packages you are using) depend
! on a combination of PHP versions and/or extensions that are
! …Run Code Online (Sandbox Code Playgroud) laravel-8 ×10
laravel ×7
php ×5
mysql ×2
composer-php ×1
docker ×1
eloquent ×1
heroku ×1
inertiajs ×1
laravel-5 ×1
laravel-sail ×1
migration ×1
mysql-8.0 ×1
php-carbon ×1
vuetify.js ×1