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 :)
Related
I used to create functions in controllers like this with Laravel 5.8 and I was able to handle when the item was not found redirecting the user to the index page with an error notification.
public function edit($id)
{
$template = Template::find($id);
if ($template) {
return view('admin.templates.edit', compact(['template']));
}
$this->setNotifications('error', 'Not found');
return redirect()->route('admin.templates.index');
}
Now with Laravel 6 the function declaration has changed and if the item is not found, it displays the default not found page directly, ignoring the code in the function and I'm not able handle the not found error as I used to do.
public function edit(Template $template)
{
if ($template) {
return view('admin.templates.edit', compact(['template']));
}
$this->setNotifications('error', 'Not found');
return redirect()->route('admin.templates.index');
}
Is there a way to use the Laravel 6 way and handle what happens when the item is not found at the same time?
I made a manyToMany relationship and want to return that in my php code which is not working, but when I run the same code in tinker it is working for some reason. What am I missing?
// Firma
public function auftraege()
{
return $this->belongsToMany("Auftrag", 'auftraege_firma');
}
// Auftrag
public function firmen()
{
return $this->belongsToMany("Firma", 'auftraege_firma');
}
// works in tinker
$firma = App\Firma::first();
$firma->auftraege
// Does not work in php Controller
$firma = App\Firma::first();
return $firma->auftraege
Getting 500 Error
Looking at your controller code, I can only notice two things. Change your controller code like this:
$firma = \App\Firma::first();
return $firma->auftraege;
You are missing \ before the App namespace and also the semicolon is missing in the return statement.
Please also change the relationshps like this:
public function auftraege()
{
return $this->belongsToMany(Auftrag::class, 'auftraege_firma');
}
public function firmen()
{
return $this->belongsToMany(Firma::class, 'auftraege_firma');
}
The reason it was working from tinker is that by default tinker sets the namespace to App for the current tinker session. That's why even though you didn't specify the App namespace, tinker was able to parse the proper namespace.
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!
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.
A while back I completed this series of tutorials and converted the jobeet from symfony 1 to symfony 2.
http://intelligentbee.com/blog/2013/08/07/symfony2-jobeet-day-1-starting-up-the-project/
I am now trying to upgrade it to 2.8
Everything works except for the lucene search.
I am attempting to implement EWZSearchBundle as a solution.
config.yml
ewz_search:
indices:
indexJob:
path: %kernel.root_dir%/EwzLuceneIndices/%kernel.environment%/myIndexJob
analyzer: Zend\Search\Lucene\Analysis\Analyzer\Common\Utf8\CaseInsensitive
# deprecated
analyzer: Zend\Search\Lucene\Analysis\Analyzer\Common\TextNum\CaseInsensitive
path: %kernel.root_dir%/cache/%kernel.environment%/lucene/index
search action in controller
public function searchAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$query = $this->getRequest()->get('query');
if(!$query) {
if(!$request->isXmlHttpRequest()) {
return $this->redirect($this->generateUrl('ibw_job'));
} else {
return new Response('No results.');
}
}
$jobs = $em->getRepository('AcmeJobeetBundle:Job')->getForLuceneQuery($query);
if($request->isXmlHttpRequest()) {
if('*' == $query || !$jobs || $query == '') {
return new Response('No results.');
}
return $this->render('AcmeJobeetBundle:Job:list.html.twig', array('jobs' => $jobs));
}
}
function in entity repository
static public function getLuceneIndex()
{
$luceneSearchForFooIndex = $this->get('ewz_search.lucene.manager')->getIndex('indexJob');
return $luceneSearchForFooIndex ;
}
The error that I get in app_dev.php
Error: Using $this when not in object context
500 Internal Server Error - FatalErrorException
I know that "$this" is out of context and that is why I am getting the error but I have absolutely no id on how to fix it.
Any help/links to docs/ideas for a solution is greatly appreciated.
Thanks in advance.
Composer Saved the Day
"sonata-project/doctrine-orm-admin-bundle": "2.3.*",
"zf1/zend-search-lucene": "~1.12"
After a day or so of trying to make the other search functions work. I was able to the the zend framework work by adding the specific framework component through composer.
It now all works in 2.8.