Laravel 5: Class 'HTML' not found - php

I'm just getting started with Laravel. I'm in a controller method and I say:
return \View::make('scrape', $data);
Then in scrape.blade.php I have:
#extends('layouts.master');
Finally, in layouts/master.blade.php I have:
{{ HTML::style('css/bootstrap.min.css') }}
And that where things seem to fall apart and I get:
FatalErrorException in 002eb18bb71fd3ec1de058967b799d49 line 6:
Class 'HTML' not found
What am I doing wrong? Thanks for your help.

Searching on google I found this
"By default in Laravel 5.0, Html and Form are not embedded anymore."
You need to add this package to you application.

Please use above links and last change HTML to Html.
eg:
{{ HTML::style('css/bootstrap.min.css') }}
to
{{ Html::style('css/bootstrap.min.css') }}.
its working.

Related

Laravel - Conditional Route Name mapping / dynamic routes

I thought to write static routes like contact, imprint or "About Us" in the web.php as a one-liner. I saw this at Laravel Daily.
web.php
Route::get('/{page}', App\Http\Controllers\StaticPageController::class)
->name('page')
->where('page', 'about-us|imprint|contact');
It's nice but I'm getting problems with my navbar.
My Blade navbar has a dynamic part. The current menu item is highlighted. Very simple.
nav.blade.php
<x-nav-link :href="route('about-us')" :active="request()->routeIs('about-us')">
{{ __('About us') }}
</x-nav-link>
With the new one-liner, I then get the following error message:
Symfony\Component\Routing\Exception\RouteNotFoundException.
Route [about-us] not defined. (View: /project01/resources/views/includes/nav.blade.php)
Which is logical, because I no longer have the about-us route.
Actually, the route should be given a corresponding array mapping. But I don't know how. How can I solve the problem?
The solution for this problem will be:
<x-nav-link :href="route('page', ['page' => 'about-us'])" :active="request()->routeIs('about-us')">
{{ __('About us') }}
</x-nav-link>
Special Thanks for all good answears!
You have two options.
1- Change the routeIs() to is() and use the path, not the route name
<x-nav-link :href="route('page', ['page' => 'about-us'])" :active="request()->is('about-us/*')">
{{ __('About us') }}
</x-nav-link>
2- Switch back to 3 routes instead of the one liner. There is no gain in using the one liner. It is slower and harder to read (maintain)
You have assigned a name page to a given route with the required parameter named page. So, you must use the following code:
route('page', ['page' => 'about-us']);
https://laravel.com/docs/6.x/routing#named-routes
I think there is a misunderstanding.'about-us|imprint|contact' is the parameter restrictions.'page' is the route name.So this should work;
<x-nav-link :href="route('page','about-us')" :active="Request::url() == route('page','about-us')">
{{ __('About us') }}
</x-nav-link>

Laravel 5.5: Paginator styles disappear

i took a screenshot from my paginator.. it looks weird
I did this on my controller:
$customers = Customer::paginate(3);
and just this on my view (out of table tags):
{{ $customers->render() }}
Same on page 1,2
What's wrong?
Already fixed adding this: {{ $customers->links('pagination::bootstrap-4') }} why laravel 5.5 makes it so difficult? i miss 5.3 =/
try this
{{$customer->links()}}
i think that paginator default laravel.

Laravel blade "{{ command }}" not working correctly

I have this weird problem with my Laravel 5.5 version... I created the auth views using
php artisan make:auth
This command created the views controllers and everything I need to lets get stared to work. But I'm having this visualization problem
As you can see on the register view I have this problem.
The real thing is that "{{ any_command }}" is printing the code that its supose to generate instead of interprating like part of the code. But if I use {!! any_command !!} instead it seems to work propertly. What can happend to my laravel is screwed up. It has nothing to be with the artisan auth method, because I tried to create a new form (using laravel collective form helper) and get the same result.
{{ }} will escape all data before printing. So, if you write any HTML tag inside, it will be escaped and printed as is. Just like your example.
{!! !!} will print unescaped data. This will print the tags correctly, but you have to take care where you use it, because someone could inject unwanted data there.
So, in your case, you should use {!! !!}.
Please, refer to this question: What is the difference between {{ }} and {!! !!} in laravel blade files?

Laravel 5 GET inside controller?

I use Laravel5 and i cant understand why postProcess or getProcess not works?
Example::
html page:
{{ Form::open(array('url' => 'portfolio/process')) }}
{{ Form::submit() }}
{{ Form::close() }}
route:
Route::resource('portfolio','PortfolioController');
controller:
public function postProcess (){
return 'Text!';
}
Every time i get error:
MethodNotAllowedHttpException in RouteCollection.php line 218:
It doesn't work because Route::resource doesn't build these routes and you need to explicitly define them:
Route::post('portfolio/process', 'PortfolioController#postProcess');
I think you need to check your route list:
Run this command php artisan route:list in terminal and check your route.
Hope this work for you!

laravel 5 Library for load CSS, JavaScript

I want to include CSS and Javascript with the help of Laravel 5 helper. But I don't know which is there.
href="{{ url() }}/assets/css/bootstrap.css" rel="stylesheet"
I need to load with the helper of laravel. Not to traditional.
Please any suggestion tell me.
In Laravel you can use the provided HTML class for including the CSS and JS in a project
Stylesheet:
{{ HTML::style('css/style.css') }}
Javascript:
{{ HTML::script('js/your_js_file.js') }}
NOTE:
You can also use URL class
JS
{{ URL::asset('js/your_js_file.js'); }}
STYLE
{{ URL::asset('css/style.css'); }}
EDIT:
If you are using LARAVEL 5 find the solution here http://laravel.io/forum/09-20-2014-html-form-class-not-found-in-laravel-5
One way is using : URL::asset('css/file.css');
For using {{ HTML::style('css/style.css') }}, you will have to go through following steps:
Add the following lines in the require section of composer.json file and run composer update "illuminate/html": "5.*".
Register the service provider in config/app.php by adding the following value into the providers array:
'Illuminate\Html\HtmlServiceProvider'
Register facades by adding these two lines in the aliases array:
'Form'=> 'Illuminate\Html\FormFacade',
'HTML'=> 'Illuminate\Html\HtmlFacade'

Categories