- ad_hitech
- Posts : 7
Join date : 2020-07-26
Age : 25
Exception generated while accessing a blade page.
Wed Jul 29, 2020 2:32 pm
I am getting this error while I am trying to access my services.blade page.
Use of undefined constant title - assumed 'title' (this will throw an Error in a future version of PHP) (View: C:\xampp\htdocs\Laravel\Laravel\resources\views\pages\Services.blade.php)
Use of undefined constant title - assumed 'title' (this will throw an Error in a future version of PHP) (View: C:\xampp\htdocs\Laravel\Laravel\resources\views\pages\Services.blade.php)
- Code:
/*My PagesController.php code*/
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class PagesController extends Controller
{
public function index(){
$title = 'Welcome To Laravel!';
//return view('pages.index',compact('title'));
return view('pages.index')->with('title',$title);
}
public function about(){
$title = 'About Us';
return view('pages.about')->with('title',$title);
}
public function services(){
$data = array(
'title' => 'Services',
'Services'=>['Web Design','Programming','SEO']
);
return view('pages.services')->with($data);
}
}
- Code:
/*My services-blade.php code
@extends('layouts.app')
@section('content')
<h1>{{title}}</h1>
@if(count($services)>0)
<ul>
@foreach($services as $service)
<li>{{$service}}</li>
@endforeach
</ul>
@endif
@endsection
- Code:
/*My web.php code
<?php
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
/*Route::get('/posts/{post}',function ($post) {
$posts = [
'my-first-post' => 'Hello,this is my first blog post!',
'my-second-post' => 'Now I am getting the hang of this blogging thing.'
];
if(! array_key_exists($post, $posts)){
abort(404,'Sorry,that post was not found.');
}
return view('post',[
'post' => $posts[$post]
]);
});*/
/*Route::get('/users/{id}/{name}',function($id,$name)
{
return 'This is user'.$name.'with an id of'.$id;
});*/
Route::get('/about',function()
{
return view('pages.about');
});
Route::get('/','PagesController@index');
Route::get('/about','PagesController@about');
Route::get('/services','PagesController@services');
- Jeetbasak54@gmail.com
- Posts : 18
Join date : 2020-07-25
Re: Exception generated while accessing a blade page.
Wed Jul 29, 2020 3:20 pm
The name of the view page should b service.blade.php
The php blade page should b present in the view folder.
To access the page 1st create a function in controller page And within the function write return view ( ''service''); the name of the page it is.
And then creat a route to access the function with url. I guess u can create route to access any function of controller.
I don't know you r making the service page. For that use Route:: get() if get not work then use post().
The php blade page should b present in the view folder.
To access the page 1st create a function in controller page And within the function write return view ( ''service''); the name of the page it is.
And then creat a route to access the function with url. I guess u can create route to access any function of controller.
I don't know you r making the service page. For that use Route:: get() if get not work then use post().
- Jeetbasak54@gmail.com
- Posts : 18
Join date : 2020-07-25
Re: Exception generated while accessing a blade page.
Wed Jul 29, 2020 3:27 pm
In your controller page in return view of service function write only service. And create that service.blade.php page in the view folder only. U don't need to create that page folder. U can try in this way.
My b it will work.
My b it will work.
- ad_hitech
- Posts : 7
Join date : 2020-07-26
Age : 25
Re: Exception generated while accessing a blade page.
Wed Jul 29, 2020 3:34 pm
Still not working.
- Jeetbasak54@gmail.com
- Posts : 18
Join date : 2020-07-25
Re: Exception generated while accessing a blade page.
Wed Jul 29, 2020 3:41 pm
Did you have a variable $title and omitted the $, or were you intending to use a string'title' and forgot the quotation marks?
Problem occurs with that title. U can try {{$ title }} in your service.blade.php page. Where u have used only {{ title}}.
Problem occurs with that title. U can try {{$ title }} in your service.blade.php page. Where u have used only {{ title}}.
ad_hitech likes this post
- ad_hitech
- Posts : 7
Join date : 2020-07-26
Age : 25
Re: Exception generated while accessing a blade page.
Wed Jul 29, 2020 4:08 pm
Exactly It is showing this error at line 4 of my services.blade.php file. well after giving the $ sign.I got it fixed.
- Jeetbasak54@gmail.com
- Posts : 18
Join date : 2020-07-25
Re: Exception generated while accessing a blade page.
Wed Jul 29, 2020 4:10 pm
Nice.
Permissions in this forum:
You cannot reply to topics in this forum
|
|