0

We are trying use bootstrap components for our fresh laravel project.

GitHub: https://github.com/appstract/laravel-bootstrap-components

we have following code in blade. but it doesn't work and have error.

blade codes:

@extends('layouts.app')
@section('page-title','Welcome')

@section('content')
    @component('bootstrap::alert', ['type' => 'danger'])
        A simple alert of danger type
    @endcomponent
@stop

error:

ErrorException (E_ERROR) Undefined variable: class (View: B:\xampp\htdocs\me2we\resources\views\vendor\bootstrap\alert.blade.php) (View: B:\xampp\htdocs\me2we\resources\views\vendor\bootstrap\alert.blade.php)

what we have to do to fix it?

Masivuye Cokile
  • 4,754
  • 3
  • 19
  • 34
Amin Shabanzadeh
  • 301
  • 2
  • 11
  • No idea, your error is not in this code. Show your full alert.blade.php. – aynber Dec 13 '18 at 13:30
  • Where did you use the $class variable? – hktang Dec 13 '18 at 13:30
  • Possible duplicate of ["Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset" using PHP](https://stackoverflow.com/questions/4261133/notice-undefined-variable-notice-undefined-index-and-notice-undefined) – aynber Dec 13 '18 at 13:33

1 Answers1

1

It seems alert.blade.php contains the following snippet:

{{ $class or '' }}

The latest version of Laravel no longer supports or between curly brackets in blade. These have been replaced by PHP 7's null coalesce operator.

So it should now be like this:

{{ $class ?? '' }}

More info: https://laravel-news.com/blade-templates-null-coalesce-operator

Jerodev
  • 32,252
  • 11
  • 87
  • 108