标签: laravel-6

Laravel 6.0.3 未加载关键资源 App.js 或 App.css 404 Not Found

要设置我的项目,我运行:

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 文件外都是空的,这正常吗?

laravel laravel-6

10
推荐指数
1
解决办法
1万
查看次数

SQLSTATE[HY000] [1045] 用户“root”@“localhost”的访问被拒绝(使用密码:NO)。DB_HOST 设置为本地主机

我知道这个问题可能已经在 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 email= user.email@gmail.com)

php mysql laravel laravel-6

10
推荐指数
3
解决办法
6万
查看次数

Laravel 5.4,5.3:自定义或扩展通知 - 数据库模型

恕我直言,当前用于在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 laravel-5 laravel-6

9
推荐指数
3
解决办法
7930
查看次数

Laravel Telescope 无法打开流:没有这样的文件或目录 TelescopeServiceProvider.php

我正在尝试使用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再次运行该命令,它向我提供了以下消息:

望远镜脚手架安装成功。

我认为这很奇怪,但好吧,我进入了文档的下一步:

  • 安装 Telescope 后,您还应该运行以下migrate命令: php artisan migrate

所以我运行了那个命令,我得到了消息:

没什么好迁移的。

所以显然这不正确。如果 TelescopeServiceProvider 现在存在,我在“假”安装成功消息后检查了它,但它仍然没有。

我做错了什么,我该如何解决这个问题?

php laravel laravel-6

9
推荐指数
1
解决办法
2057
查看次数

Laravel - 尝试访问 int 类型值的数组偏移量

当我尝试向数据库提交发布请求时遇到问题。有趣的是,该错误仅在我使用 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)

php laravel laravel-6 php-7.4

9
推荐指数
2
解决办法
4万
查看次数

Laravel 6中未定义工匠命令“ make:auth”

在Laravel 6中创建登录/身份验证时遇到问题。我在终端中键入“ make:auth”,但出现错误“命令” make:auth“似乎未定义”。有解决方案吗?

laravel laravel-6

8
推荐指数
4
解决办法
1万
查看次数

如何在 Laravel 中使用 app.js 和 app.css 修复错误 404?

我正在使用 Laravel 6 和 Bootstrap 4。

我制作了一个小应用程序,试图更改 CSS 文件中主体的背景颜色,但我发现它不起作用。

所以我检查了开发人员的工具,发现有两个关于app.jscss/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)

javascript css twitter-bootstrap laravel laravel-6

8
推荐指数
1
解决办法
2万
查看次数

在路由中添加参数的位置:verification.notice {language}/email/verify

缺少 [路由: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

8
推荐指数
1
解决办法
1776
查看次数

工会中的 Laravel 关系冲突

我有以下模型: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)

php mysql laravel eloquent laravel-6

8
推荐指数
1
解决办法
560
查看次数

从Laravel 5.8升级到6.2后,ConfirmPasswordController不存在

我正在开发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下次我要面对很多问题。有人会建议我正确的流程,我应该怎么做?

laravel laravel-upgrade laravel-6

7
推荐指数
1
解决办法
405
查看次数