Syntax error in server not on localhost - laravel

I have this link:
List of all members
and this route:
Route::get('/list', 'NyfnController#list');
controller method:
public function list()
{
$users=User::orderBy('district_involved')->get();
return view('list')->with('users',$users);
}
But, i got the syntax error:
syntax error, unexpected 'list' (T_LIST), expecting identifier
(T_STRING)
This works fine on localhost, but not on server.

Probably your localhost is running 5.6.4> and your webserver is running 7.*.
In php 7 the list method is not available. If you use PHPStorm you got a notice that list is a new method in PHP 7 (or newer). Have a look at: http://php.net/manual/en/function.list.php#refsect1-function.list-changelog
I would recommend you to change you method:
public function listUsers()
{
$users=User::orderBy('district_involved')->get();
return view('list')->with('users',$users);
}
Route::get('/list', 'NyfnController#listUsers');

It happens that list is a reserved word (http://php.net/manual/en/function.list.php), actually a language construct, and therefore you cannot define a function with that name. Use whatever other (not reserved) name you want.

Related

Laravel Spotify gives error - even when following Github

So I'm using this package: https://github.com/aerni/laravel-spotify for a project, and I've followed the "Usage-steps", but I keep getting this error:
Non-static method Aerni\Spotify\Spotify::searchTracks() should not be called statically
when I do it the way the package says.
This is my code:
public function index()
{
$variable = Spotify::searchTracks('Wish You Were Here')->get();
dd($variable);
return view('pages.index');
}
with
use Aerni\Spotify\Spotify;
on top of the file. Because of the error I tried this:
(new Spotify)->searchTracks('Wish You Were Here')->get();
but I get this error:
Too few arguments to function Aerni\Spotify\Spotify::__construct(), 0 passed in C:\ProjectDirectory\hetplatenhuis-newversion\app\Http\Controllers\Pages\IndexController.php on line 13 and exactly 1 expected
Is there anyone who has experience with this package?

I have a problem with optional parameters that gives 404 error in laravel 7

I have the following function in laravel 7:
public function create(Franchise $franchise = null)
{
...
}
And the route is as follows:
Route::get('series/create/{franchise?}', 'SerieController#create')->name('serie.create');
when I execute it with parameters for example page_name/series/create/1 it executes normally but when I execute without parameters page_name/series/create I get an error 404 | Not Found.
I also used dd() at the beginning of the function and it keeps giving me the same error
I also did the same with index:
Route::get('series/{franchise?}', 'SerieController#index')->name('serie');
And there it executes me well with or without parameters
Is there a route problem?
it seems you didn't add /series/create to your router. This is the reason why Laravel doesn't see this route and throws a 404 error. Add that route to your router file:

Having trouble with Model Bind - Laravel Breadcrumbs

Having trouble with Model Bind on davejamesmiller/laravel-breadcrumbs.
I'll try to be brief, but if you need more data just ask =D
This is my controller/action signature:
public function edit(Request $request, Vertical $vertical, UserMacro $macro)
And this is my BC for the corresponding route:
Breadcrumbs::register('macro-edit', function (Generator $breadcrumbs, $vertical, $macro) {
$breadcrumbs->parent('macro-index');
$breadcrumbs->push($macro->name, route('macro-edit', [$vertical->_id, $macro]));
});
I'm getting the string ID on $vertical and $macro, breaking on $macro->name. If I add Hints as the action have I get aType error.
Trying to get property of non-object (View: /.../resources/views/layouts/app.blade.php) (View: /.../resources/views/layouts/app.blade.php)
Type error: Argument 2 passed to DaveJamesMiller\Breadcrumbs\BreadcrumbsServiceProvider::{closure}() must be an instance of App\Vertical, string given, called in /.../vendor/davejamesmiller/laravel-breadcrumbs/src/BreadcrumbsGenerator.php on line 68 (View: /.../resources/views/layouts/app.blade.php) (View: /.../resources/views/layouts/app.blade.php)
I didn't analyze core code of library, so i don't know why controllers work, but breadcrumbs don't. Recipe to working model binding is use proper route naming convention.
Breadcrumbs::for('messages.show', function($trail, \App\Models\MassMessage $massMessage) {
$trail->parent('Index');
$trail->push('Show', route('messages.show', $massMessage));
});
Route::get('messages/{massMessage}', 'MessageController#show')->name('messages.show');
// error (controllers are fine)
Route::get('mass-mmessages/{massMessage}', 'MessageController#show')->name('messages.show');
// works both
The same problem is with resource route.
edit:
I was wrong. Controller also doesn't work. It not raise error but it pass empty Eloquent object. In my case i needed to change $massMessage variable's name into $message in both places and works fine, now.

Laravel 4 route-model binding exceptions doesn't work despite docs and examples

I read a lot about Laravel4 Route-model binding (L4 docs, tutorials, etc.) but still exceptions (i.e. the model is not found) don't work for me
These are my basic files
routes.php:
Route::model('game', 'Game', function(){
// override default 404 behavior if model not found, see Laravel docs
return Redirect::to('/games');
});
...
Route::get('/games/edit/{game}', 'GamesController#edit');
GamesController.php
class GamesController extends BaseController {
...
public function edit(Game $game){
return View::make('/games/edit', compact('game'));
}
}
Pretty straight, but I get this error: Argument 1 passed to GamesController::edit() must be an instance of Game, instance of Illuminate\Http\RedirectResponse given
If I type http://mysite.dev/games/edit/1 all is fine (model with ID = 1 exists)
If I type http://mysite.dev/games/edit/12345 (no model with that ID) the ugly error above is triggered instead of the redirect I specified
I also looked at this (the bottom part where a Redirect closure is suggested: that is just what I am doing!) but no way to make it work: laravel 4 handle not found in Route::model
What's wrong with it? Please any help?
Thanks in advance
In Route::model you declare which variable will be a model instance, you shouldn't use it to do a redirection that way. Instead of that, specify that $game is of type Game and then work with your routes:
Route::model('game', 'Game');
...
Route::get('/games/edit/{game}', 'GamesController#edit');
Then if you access to /games/edit/3 GamesController::edit will receive an instance of Game class whose id=3
I ended up by setting a general "Not Found" error catcher, like this:
// routes.php
App::error(function(Symfony\Component\HttpKernel\Exception\NotFoundHttpException $e) {
return Response::make('Not Found', 404);
});
...
Route::model('game', 'Game');
...
Route::get('/games/edit/{game}', 'GamesController#edit');
What I understand is that if I want a custom redirect and not a general 404 page (i.e. take the user to games' list if model not found), I CAN'T use the route-model-binding
In other words, I have to use Route::get('/games/edit/{id}', 'GamesController#edit'); and then do my application logic inside the 'edit' method:
public function edit($id){
$game = Game::findOrFail($id);
// if fails then redirect to custom page, else go on saving
}
I'm very new to Laravel, but as far as I can see this has nothing to do with the closure, but with the use of "Redirect::to" inside that closure. Using "App::abort( 404 );" works.

Mailgun Laravel

I installed Mailgun for Laravel. I then tried to run the example
$data = [];
Mailgun::send('emails.welcome', $data, function($message)
{
$message->to('foo#example.com', 'John Smith')->subject('Welcome!');
});
But I got the following error:
"Argument 1 passed to Bogardo\\Mailgun\\Mailgun::__construct() must be an instance of Illuminate\\View\\Environment, instance of Illuminate\\View\\Factory given, called in /Users/koushatalebian/CLG/CL2G/app/vendor/bogardo/mailgun/src/Bogardo/Mailgun/MailgunServiceProvider.php on line 33 and defined"
What is going on?
If you are using Laravel 4.2, Please use Illuminate\View\Factory instead of Illuminate\View\Environment.
Bogardo mail gun package pointing wrong file.
/Users/koushatalebian/CLG/CL2G/app/vendor/bogardo/mailgun/src/Bogardo/Mailgun/MailgunServiceProvider.php
View / Pagination Environment Renamed
If you are directly referencing the Illuminate\View\Environment class or
Illuminate\Pagination\Environment class, update your code to reference Illuminate\View\Factory and
Illuminate\Pagination\Factory instead. These two classes have been renamed to better reflect their
function.
Edit:
You can use the correct class by editing the following file:
vendor/bogardo/mailgun/src/Bogardo/Mailgun/Mailgun.php
in Line 5:
remove use Illuminate\View\Environment; and use use Illuminate\View\Factory;
in line 53:
remove
public function __construct(Environment $views)
{
$this->views = $views;
}
use
public function __construct(Factory $views)
{
$this->views = $views;
}
Hope this will fix.

Resources