要设置我的项目,我运行:
laravel new cms
composer require laravel/ui
php artisan ui:auth
php artisan migrate
Run Code Online (Sandbox Code Playgroud)
但是,当我访问http://cms.test/login时,会看到登录页面:
并因缺少资源而得到两个 404 错误:
http://cms.test/js/app.js net::ERR_ABORTED 404 (Not Found)
http://cms.test/css/app.css
Run Code Online (Sandbox Code Playgroud)
这些丢失文件的原因可能是什么?
我的公共目录除了.htaccess、favicon.ico、index.php 和robot.txt 文件外都是空的,这正常吗?
我知道这个问题可能已经在 stackOverflow 中找到了答案。但我在这里有不同的问题。我将 laravel 项目从 localhost 移到了 server 。我在服务器中完成了每一步。我可以在我的服务器中查看登录页面。问题是,我无法连接到我的 mysql 服务器。我的.env文件。
APP_NAME=Transport
APP_ENV=local
APP_KEY=base64:mrakeyidharhaikonsdf
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=transport_db
DB_USERNAME=root
DB_PASSWORD=mypass
Run Code Online (Sandbox Code Playgroud)
我尝试将主机更改为127.0.0.1并尝试放置我服务器的 ip 。它没有帮助我。我错过了什么吗?
我的错误:
SQLSTATE[HY000] [1045] 用户 'root'@'localhost' 的访问被拒绝(使用密码:NO)(SQL:选择 count(*) 作为聚合来自
userswhere
恕我直言,当前用于在Laravel中保存通知的数据库通道是非常糟糕的设计:
data列中搜索自定义属性(转换为Array)不是最佳选择您将如何DatabaseNotification在供应商包中扩展模型?
我想添加列event_id,question_id,user_id(在创建该通知用户)等等为默认laravel notifications表
如何覆盖send函数以包含更多列?
在:
vendor/laravel/framework/src/Illuminate/Notifications/Channels/DatabaseChannel.php
Run Code Online (Sandbox Code Playgroud)
代码:
class DatabaseChannel
{
/**
* Send the given notification.
*
* @param mixed $notifiable
* @param \Illuminate\Notifications\Notification $notification
* @return \Illuminate\Database\Eloquent\Model
*/
public function send($notifiable, Notification $notification)
{
return $notifiable->routeNotificationFor('database')->create([
'id' => $notification->id,
'type' => get_class($notification),
\\I want to add these
'user_id' => \Auth::user()->id,
'event_id' => $notification->type =='event' ? $notification->id : null,
'question_id' => $notification->type =='question' ? …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Laravel 官方文档中的 Telescope 包,我遵循了前两个步骤:
composer require laravel/telescope
Run Code Online (Sandbox Code Playgroud)
和
php artisan telescope:install
Run Code Online (Sandbox Code Playgroud)
在安装之前,我的命令行中一切正常。我得到了错误:
ErrorException : file_get_contents(path\app\Providers/TelescopeServiceProvider.php: 无法打开流:没有这样的文件或目录:vendor\laravel\telescope\src\Console\InstallCommand.php
所以,当然,我用谷歌搜索了这个问题并找到了这个,我检查了我的提供者的文件夹是否存在。它确实存在并且确实TelescopeServiceProvider.php不存在。我尝试php artisan telescope:install再次运行该命令,它向我提供了以下消息:
望远镜脚手架安装成功。
我认为这很奇怪,但好吧,我进入了文档的下一步:
migrate命令:
php artisan migrate所以我运行了那个命令,我得到了消息:
没什么好迁移的。
所以显然这不正确。如果 TelescopeServiceProvider 现在存在,我在“假”安装成功消息后检查了它,但它仍然没有。
我做错了什么,我该如何解决这个问题?
当我尝试向数据库提交发布请求时遇到问题。有趣的是,该错误仅在我使用 PHP 7.4.2 版时发生。在 PHP 7.3.9 版中一切正常。我正在使用 Laravel 6.17。
Laravel 什么时候会修复这个问题?
这是我的堆栈跟踪,当错误出现时。
Trying to access array offset on value of type int
in CreateCourseController.php line 176
at HandleExceptions->handleError()
in CreateCourseController.php line 176
at CreateCourseController->createDates()
in CreateCourseController.php line 101
at CreateCourseController->createCourse()
at call_user_func_array()
in Controller.php line 54
at Controller->callAction()
in ControllerDispatcher.php line 45
at ControllerDispatcher->dispatch()
in Route.php line 219
at Route->runController()
in Route.php line 176
at Route->run()
in Router.php line 681
at Router->Illuminate\Routing\{closure}()
in Pipeline.php line 130
at Pipeline->Illuminate\Pipeline\{closure}()
in SubstituteBindings.php …Run Code Online (Sandbox Code Playgroud) 在Laravel 6中创建登录/身份验证时遇到问题。我在终端中键入“ make:auth”,但出现错误“命令” make:auth“似乎未定义”。有解决方案吗?
我正在使用 Laravel 6 和 Bootstrap 4。
我制作了一个小应用程序,试图更改 CSS 文件中主体的背景颜色,但我发现它不起作用。
所以我检查了开发人员的工具,发现有两个关于app.js和css/app.css的错误
“无法加载资源:服务器响应状态为 404(未找到)”
我尝试在 CSS 路径之前添加“/” ,但失败了。
看法:
<!doctype html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- CSRF Token -->
<meta name="csrf-token" content="{{ csrf_token() }}">
<title>{{ config('app.name', 'Laravel') }}</title>
<!-- Scripts -->
<script src="{{ asset('js/app.js') }}" defer></script>
<!-- Fonts -->
<link rel="dns-prefetch" href="//fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet">
<!-- Styles -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link href="{{ asset('css/app.css') }}" rel="stylesheet" type="text/css"> …Run Code Online (Sandbox Code Playgroud) 缺少 [路由:verification.notice] [URI:{语言}/email/verify] 所需的参数
使用本地化后,我将 laravel 电子邮件验证添加到我的项目中。但现在我遇到了 Route:verification.notice 缺少参数的问题。我知道我需要将 app()->getLocale() 参数添加/传递到路线,但找不到位置
我尝试搜索项目中的所有路由和 URL,并检查了 VerificationController.php 和 verify.blade.php。但我没有找到缺少参数的路线。另外,我在网上找不到有同样问题的人。
网页.php
Route::group([
'prefix' => '{language}',
'where' => ['{language}' => '[a-Za-Z]{2}'],
'middleware' => 'SetLanguage',
],
function () {
Route::get('/', function () {
return view('welcome');
})->name('Welcome');
Auth::routes(['verify' => true]);
Route::get('/home', 'HomeController@index')->name('home');
Route::namespace('User')->group(function () {
Route::get('/profile', 'UserController@editProfile')->name('profile');
Route::put('profile', 'UserController@updateProfile');
});
Route::namespace('Admin')->group(function () {
Route::get('/dashboard', 'AdminController@index')->name('dashboard');
});
});
Run Code Online (Sandbox Code Playgroud)
用户控制器
class UserController extends Controller
{
public function __construct()
{
$this->middleware('verified');
}
public function editProfile()
{
$user = User::where('id', Auth()->user()->id)->first(); …Run Code Online (Sandbox Code Playgroud) laravel-localization laravel-blade laravel-authentication laravel-6
我有以下模型:1-用户模型
/**
* Define user and functional area relationship
*/
public function functionalAreas()
{
return $this->belongsToMany('App\FunctionalArea', 'user_functional_areas', 'user_id', 'functional_area_id')->withPivot('id', 'is_primary')->withTimestamps();
}
Run Code Online (Sandbox Code Playgroud)
和商业模式:
/**
* Define business and user functional area relationship
*/
public function functionalAreas()
{
return $this->belongsToMany('App\FunctionalArea', 'business_functional_areas', 'business_id', 'functional_area_id')->withTimestamps();
}
Run Code Online (Sandbox Code Playgroud)
现在我应该将所有企业和用户显示在一个列表中,为此我使用来自 union,以下是我的查询:
public function usersAndOrganizations()
{
$users = $this->users();
$organizations = $this->organizations();
$invitees = $users->union($organizations)->paginate(10);
return response()->json($invitees);
}
private function users()
{
$users = User::byState($approved = true, 'is_approved')
->search()->select([
'id',
DB::raw("CONCAT(first_name, ' ', last_name) AS name"),
'about',
'address', …Run Code Online (Sandbox Code Playgroud) 我正在开发Laravel 5.8中的项目,最近,我也将其软件包依赖版本升级到了Laravel 6.0。该项目运行良好。但是,今天,我通过更新了作曲家,composer update,并将其升级为Laravel 6.2。之后,我遇到了一个错误:
App \ Http \ Controllers \ Auth \ ConfirmPasswordController不存在
然后,我通过安装了新的Laravel-6.2生成的基本脚手架,php artisan ui vue,然后通过生成了login/registration脚手架。php artisan ui vue --auth.之后,我发现ConfirmPasswordController.然后,我ConfirmPasswordController在运行的项目中手动创建并将所有代码复制ConfirmPasswordController到手动创建的代码中,ConfirmPasswordController.然后错误消失了。尽管我没有遇到与此相关的任何错误。但是,我对自己的方法感到困惑。我的做法正确吗?或者它有解决此问题的更好方法。我很困惑,如果php artisan ui vue --auth下次我要面对很多问题。有人会建议我正确的流程,我应该怎么做?