Laravel 5.8中引入parsley.css/js失败问题求助
Hey there! Let's work through this resource loading problem step by step—since you're new to Laravel and working with 5.8, there are a few common checks we can run to get your styles and scripts loading correctly.
1. Verify Laravel Collective Setup First
First off, make sure you've installed the correct version of the Collective package for Laravel 5.8. You should have laravelcollective/html": "^5.8.* in your composer.json file. If not, run this command to install the right version:
composer require laravelcollective/html:5.8.*
Next, confirm the package is registered in your app config (config/app.php):
- Add this to the
providersarray:Collective\Html\HtmlServiceProvider::class, - Add these to the
aliasesarray:'Form' => Collective\Html\FormFacade::class, 'Html' => Collective\Html\HtmlFacade::class,
If you've made changes to config/app.php, clear your config cache to apply them:
php artisan config:clear
2. Double-Check Your Resource File Paths
Laravel's asset() helper (and Collective's Html::style/Html::script under the hood) points directly to the public directory in your project. So:
- Your
parsley.cssmust be located atpublic/css/parsley.css - Your
parsley.min.jsmust be located atpublic/js/parsley.min.js
If you accidentally placed these files in resources/assets instead, you'll need to use Laravel Mix to compile them into the public directory. For example:
- Add this to your
webpack.mix.js:mix.css('resources/assets/css/parsley.css', 'public/css'); mix.js('resources/assets/js/parsley.min.js', 'public/js'); - Run
npm run devto compile the assets, then use themix()helper instead ofasset():<link href="{{ mix('css/parsley.css') }}" rel="stylesheet"> <script src="{{ mix('js/parsley.min.js') }}"></script>
3. Inspect the Generated URL and Check for 404s
Right-click your page and select "View Page Source" to look at the actual URL generated by asset() or Html::style. For example, it should look like http://your-app-url/css/parsley.css.
Copy that URL and paste it directly into your browser's address bar. If you get a 404 error:
- The file is missing from the
publicdirectory (go back to step 2) - There's a permission issue on your
public/cssorpublic/jsdirectories. Fix this with:chmod -R 755 public/css public/js
4. Clear Browser and Laravel Caches
Sometimes old cached assets can prevent new files from loading:
- Force-refresh your browser (Ctrl+F5 on Windows, Cmd+Shift+R on Mac) to bypass browser cache
- If you've run
php artisan config:cacheorphp artisan route:cachebefore, clear those caches:php artisan cache:clear php artisan view:clear
5. Test with a Simple File
To rule out issues with the Parsley files themselves, create a test file public/css/test.css with some basic styles:
body { background: red; }
Then load it with:
<link href="{{ asset('css/test.css') }}" rel="stylesheet">
If this works, the problem is specific to your Parsley files (maybe they're corrupted or misnamed). If it doesn't, we know the issue is with your Laravel asset setup.
Let me know which step uncovers the problem—happy to help further if you hit a snag!
内容的提问来源于stack exchange,提问作者Franz

