I can't create a view in Laravel - php

I'm new in Laravel and I'm trying to create a View in Acelle (app based on Laravel). I read a lot of tutorials, but I've not been luck with this problem.
I created the view "lol.blade.php" on /resources/views folder with this code:
HELLO (just hello)
The Route:
Route::get('lol', function()
{
if (view()->exists('lol')) {
//return 'helloooo'; <--- it works
return view('lol');
} else {
return 'not exists';
}
});
The code knows the view exists, but the url (localhost/acelle/public/lol) prints this message:
"Whoops, looks like something went wrong."
I can't solve the problem with tutorials. I followed all the steps about creating views in Laravel, but I don't know why the view prints that message.
Please help!
PS: Laravel version: 5.2.45
EDIT:
In console [network] shows Error 500. and laravel.log prints 59 lines. but the first line show:
[2017-07-14 14:08:20] production.ERROR: ErrorException: Undefined index:controller in /home/acelle/public_html/acelle/app/Providers/AppServiceProv‌​ider.php:20

You posted this in the comments:
app('view')->composer('*', function ($view) {
$action = app('request')->route()->getAction();
$controller = class_basename($action['controller']);
list($controller, $action) = explode('#', $controller);
$view->with(compact('controller', 'action'));
});
Your issue is that this route uses a closure, and has no controller:
Route::get('lol', function() {});
Therefore, $action['controller'] doesn't exist and throws a warning as a result. You'll want to check isset($action['controller']) before doing the rest of your code that uses the controller variable.

Already solved!!
SOLUTION:
creating a controller : MiwebController.php
<?
namespace Acelle\Http\Controllers;
class MiwebController extends Controller
{
public function __construct()
{
parent::__construct();
$this->middleware('auth');
}
public function index()
{
return view('lol');
}
}
?>
routes.php:
Route::get('lol', 'MiwebController#index');
It works fine. Thank you!

Related

I am struggling in getting api any function

I am calling this function:
Route::get('/person', function (){
$person=[
'first_name'=>'dildar',
'last_name'=>'Muhammad',
];
return $person;
});
and I browse https://astrolabe.ml/api/person but I got error not found page 404
it does work on new laravel project but I did not found any clue from that why it does not my work.
Update your code
Route::get('/person', function (){
$person=[
'first_name'=>'dildar',
'last_name'=>'Muhammad',
];
return response()->json($person); // Update this thing
});
emphasized texttry to replace this
Route::get('/person', function (){
to
Route::get('person', function (){
Edit:
remove everything and try this:
Route::get('test', 'HomeController#index');
HomeController.php
public function index(){
dd('x');
}
then run:
php artisan optimize
finally go to www.example.com/api/test

Laravel Mail:: inside function creates error

I am making my own package.
I simplified the code to explain the weird error.
I have a simple method inside a simple controller. First, i am sending an email (printing in laravel.log) and works fine.
public function signup(){
Mail::send('vendor.proto.register.emails.proto-register-new-account', [], function ($m) {
$m->from('noreply#test.com', 'Hello');
$m->to('sfs#dgf.c', 'pepe')->subject('Test. Congratulations, your account was created');
});
return view('view path');
}
But when i want to move the Mail:: to a private method like this.
public function signup(){
$this->sendNotification2();
return view('view path');
}
public function sendNotification2(){
Mail::send('vendor.proto.register.emails.proto-register-new-account', [], function ($m) {
$m->from('noreply#test.com', 'Hello');
$m->to('sfs#dgf.c', 'pepe')->subject('Test. Congratulations, your account was created');
});
}
It crash an print the error
FatalErrorException in ClassLoader.php line 373: Maximum function nesting level of '100' reached, aborting!
Is it a bug? or i am doing something wrong ?
Solution.
Googling i found this solution. Notice i am using laravel 5.2 and php 5.6.7
Add in bootstrap\autoload.php this code ini_set('xdebug.max_nesting_level', 200); and it fix the problem.

Laravel HTTP status code "1" is not valid error

I'm trying to access my url at: http://localhost/app/public/questions/1
My Routes
$this->get('/questions/{question_id}','questionController#show');
My controller
public function show($question_id) {
$showQuestion=questions::findOrFail($question_id);
return redirect('questions',compact('showQuestion'));
}
For some reason I'm getting this error
InvalidArgumentException in Response.php line 458:
The HTTP status code "1" is not valid.
What could be the problem?
I guess you are trying to return a view
public function show($question_id) {
$showQuestion=questions::findOrFail($question_id);
return view('questions')->with('question', $showQuestion);
}
Source
After having something similar myself, maybe you should be using:
return redirect('questions')->with('showQuestion', $showQuestion);

CakePHP3 - Custom page error 404 not working

I doing tutorial follow http://book.cakephp.org/3.0/en/development/errors.html#exception-renderer but it is not working and display blank page.
In config/bootstrap.php
use App\Error\AppError;
$errorHandler = new AppError();
$errorHandler->register();
In src/Error/AppError.php
<?php
namespace App\Error;
use Cake\Error\BaseErrorHandler;
class AppError extends BaseErrorHandler
{
public function _displayError($error, $debug)
{
return 'There has been an error!';
}
public function _displayException($exception)
{
return 'There has been an exception!';
}
public function handleFatalError($code, $description, $file, $line)
{
return 'A fatal error has happened';
}
}
I create my_error.ctp in src/Template/Layout/my_error.ctp. And in my src/Template/Error/error404.ctp I change layout to my_error.ctp.
$this->layout = 'my_error';
Finally, In my controller
use Cake\Network\Exception\NotFoundException;
$staff = $this->Staff->find()->where(['Staff.StaffId = '=> $id, 'Staff.PartnerId = ' =>$this->partnerId])->first();
if (empty($staff)) {
throw new NotFoundException(__('Staff not found'));
}
Whenever encountering blank pages, enabled debug mode, visit the URL again, and check your error logs.
However, problem in this case is most likely that the docs are incorrect/misleading, as the example app error won't do anything at all. The _ prefixed methods are ment to be protected, having them return something has no effect, and handleFatalError is ment to return a boolean.
Just look at the source of Cake\Error\BaseErrorHandler and the core error handler Cake\Error\ErrorHandler, the methods that you are overwriting are ment to generate output!
You may want to report that as an issue over at GitHub.
If all you want to do, is create a custom 4xx error page, then all you need to do is to edit the src/Template/Error/error400.ctp template accordingly.
I found my mistake. :(
Because in bootstrap.php I copy below code at the end of file. Therefore Cake cannot understand it. Please close this issue. Thank you for support.
use App\Error\AppError;
$errorHandler = new AppError();
$errorHandler->register();

Laravel throws NotFoundHttpException on a resource

This is my URL:
http://serverHost:port/projectName/public/restaurants/create
This is the error message:
Open: UrlToProject\bootstrap\compiled.php
if (!is_null($route)) {
return $route->bind($request);
}
$others = $this->checkForAlternateVerbs($request);
if (count($others) > 0) {
return $this->getOtherMethodsRoute($request, $others);
}
throw new NotFoundHttpException();
}
protected function checkForAlternateVerbs($request)
Though the route does exist like this:
Route::resource('restaurants', 'RestaurantsController');
and the controller RestaurantsController has this method:
public function create()
{
return View::make('restaurants.create');
}
and the view absolutely exists. What am I doing wrong please?
I am working on Laravel 4.2.3 on Windows 7.
Also, I noticed these lock signs. is this wrong?
I found the problem myself
The project name has a capital letter case and I was calling it small letter :)

Categories