Laravel Error: Call to undefined method class::seeJsonStructure() - laravel

do i need to use some namespaces or something?
here's the code:
$response = $this->call('POST', 'admin/apps/list', []);
$this->seeJsonStructure([...]);

seeJsonStructure is not available until Laravel 5.2.
You need to upgrade the Laravel version to 5.2.
Since Laravel 5.4, it has been renamed to assertJsonStructure().

Related

Call to undefined function factory()

Environment: Laravel Framework Lumen (8.2.2) (Laravel Components ^8.0)
When I run
$blogs = factory('App\Blog', 2)->create();
in BlogsControllerTest.php, it shows
Call to undefined function factory()
As Laravel's upgrade guide says the Model factory was changed.
The new way is like this App\Models\Blog::factory()->count(3)->create();
To use old version referrer to documentation.
However, to ease the upgrade process, a new laravel/legacy-factories package has been created to continue using your existing factories with Laravel 8.x
To install it use composer composer require laravel/legacy-factories
Answering my own question in case it helps somebody.
It works this way too.
$blogs = BlogFactory::new()->count(2)->create();
ref: laravel.com/docs/8.x/database-testing#connecting-factories-and-models

"Call to undefined function str_slug()" in Laravel 6.0

I've upgraded my laravel 5.8 project to 6.0. It has upgraded successfully but when I'm trying to run the project or installing another package to my project it is giving me error named as "Call to undefined function str_slug()" in session.php. I don't know why....
Call to undefined function str_slug()
If you have gone through the upgrade guide then you must know that
String and Array Helpers have been removed from Core Framework
So if if You need to still use the helper install the package
composer require laravel/helpers
and all the helpers are moved to this package
String and Array helpers are removed from laravel 6.0 Core Framework
https://laravel.com/docs/6.0/upgrade#helpers
So if You need to still use the helper install the package
composer require laravel/helpers
Or you can use by Laravel facade
use Illuminate\Support\Str;
$slug = Str::slug('Laravel 5 Framework', '-');
Personal I hard to do the following on Laravel 6
on the app Controllers add this use Illuminate\Support\Str; then
something like this 'slug' => Str::slug($request->title)
There are two options to resolve the issue of call to undefined function str_slug().
1.You should run the command composer require laravel/helpers
Or another option is when you don't want to install packages then this below solution is the easy way to solve your issue and it is the best way.
2.You can use facades class
use Illuminate\Support\Str;
public function index(Request $request)
{
$slug = Str::slug($request->name);
}
$post = Post::create([
'slug' => S t r::slug($request->title),
here we go
composer require laravel/helpers
php artisan optimize:clear

Datattables Laravel 5.4 - FatalThrowableError Call to undefined function App\Http\Controllers\Datatables()

I'm using datatables with laravel 5.4, but when I use the datatables()->query():
in providers: Yajra\Datatables\DatatablesServiceProvider::class,
in aliases: 'Datatables' => Yajra\Datatables\Facades\Datatables::class,
My code:
return Datatables()->query( /**query**/ )
return this error in my console:
FatalThrowableError
App\Http\Controllers\Datatables()
I've tried datatables() and Datatables()
Someone with the same problem?
This error happens because Laravel cannot find your package Datatables.
Laravel in controllers, if you are not mapping your classes correctly will always seek the called classes at this point App\Http\Controllers.
Just put use DataTables; or use \Yajra\Datatables\Datatables; at the start of your controller and it shall be fixed. documentation
When you install any package through composer, composer uses namespace to find the package and route functions and classes to it.
you can read more about the namespaces from php.
and you can check this tutorial for namespaces.
Also, Laravel follows the PSR 4 when it comes to autoloading, you can check it from here

Laravel 5.3 Route::resource without REST

I upgrade Laravel 5.1 to 5.3 and have some problem with routes.
In Laravel 5.1 I have route like:
Route::controllers([
'pages/{page_type}' => 'Admin\AdminPagesController',
]);
And in controller I have methods like:
getIndex($type)
postIndex($type, Request $request)
getAdd($type)
postAdd(Request $request)
getEdit($type, $id)
postEdit(Request $request, $id) and others...
But in 5.3 when I created routes:
Route::resource('pages/{page_type}', 'Admin\AdminPagesController');
I got an error
NotFoundHttpException in RouteCollection.php line 161:
or
Route pattern "/master/pages/{page_type}/{{page_type}}" cannot reference variable name "page_type" more than once.
and it generate me route in RESTful
Can anyone help me?
Thanks.
Since there is not alternative to ::controller you need to create separate route for each action if you don't want to use rest:
Route::get('pages/{page_type}', 'Admin\AdminPagesController#getIndex');
Route::post('pages/{page_type}', 'Admin\AdminPagesController#postIndex');
....
Seems that Route::controllers method has been removed in Laravel 5.2, I can't find it in the documentation since then, and doesn't exist in the Illuminate\Routing\Router.php file in Laravel 5.3
You will have to create each route separately for your case. Or you can simply use the Route::resource method, what do you have against it? You can add extra methods to a resource declaring them before the Route::resource call.

how to access to $_GET in Laravel 5.2

I have a little project on Laravel 5.1
And I updated it to 5.2
And now I get this error from my model:
Class 'Input' not found
And this is the code :
if ( \Input::get('angular') ) { ... }
And where do I find it in the documentation ?
I'm new with Laravel
And I didn't find it
Thanks for the help
You need to use:
\Request::input('angular')
instead of
\Input::get('angular')
Reference: Laravel 5.2 Request documention

Resources