Reputation: 5
web.php
Route::group(['middleware' => ['auth','Admin']], function () {
...
Route::get('/foo/fp',['uses' => 'ProgramReportController@getFp', 'as' => 'foo.getfp']);
});
ProgramReportController.php
class ProgramReportController extends Controller
{
...
public function getFp() {
$data = Fpchart::select('*')->get()->toArray();
$data = json_encode($data);
return view('foo.fp',compact('data'));
}
}
foo\fp.php
@extends('layouts.foo')
@section('content')
<script>
var data = {!!$data!!};
console.log(data);
</script>
@endsection
layouts\foo.blade.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Foo</title>
<!-- Bootstrap core CSS -->
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" ></script>
<script src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js"></script>
<script src="{{asset('js/custom.js')}}"></script>
<link href="{{asset('css/styles.css')}}" rel="stylesheet">
</head>
<body>
@yield('content')
<footer class="footer">
<div class="container">
<span class="text-muted">
<strong style="font-size: 78%;">
<a href="#">ABOUT</a>
<a href="#">PRIVACY</a>
<a href="#">TERMS</a>
<div class="pull-right">© 2020 FOO</div>
</strong>
</span>
</div>
</footer>
</body>
</html>
I'm only getting a white page and when I go to localhost:8000/foo/fp and the layout isn't loading. All I'm seeing in the page is this...
@extends('layouts.ched') @section('content') @endsection
And I'm getting this error in my console:
Uncaught SyntaxError: Unexpected token '!' on line 4 in fp.php
I tried every way of clearing my cache
php artisan optimize
php artisan cache:clear
php artisan config:clear
php artisan route:clear
php artisan view:clear
but to no avail, nothing happened. When I go to other pages under the admin middleware, the pages are loading fine except for this, so I thought maybe that it's a cache problem but I've tried everything.
Upvotes: 0
Views: 1121
Reputation: 40673
You can only use blade directives in .blade.php
files:
Rename fp.php
to fp.blade.php
and that should work
Upvotes: 1