Laravel error when using Route::resources('book', 'BookController'); - laravel-5

Super new to laravel .So I put Route::resources('books','BookController');
in my web.php but I am getting an error in my terminal (img)
also when i run my local host I get something similar (img)

Route::resource('resource', 'Controller');
resource not resources, resources would be for setting up multiple resources at one go:
Route::resources([
'something' => 'SomethingController',
'resource' => 'ResourceController',
]);
Laravel 5.5 - Docs- Controllers - Resource Controllers

Do Like this
Route::resource('itemCRUD','ItemCRUDController');
http://itsolutionstuff.com/post/crud-create-read-update-delete-example-in-laravel-52-from-scratchexample.html

Related

Fatal error with Stripe Class 'Stripe\Stripe' not found

I'm trying to implement Stripe Checkout into my website. In local the api work normal but in host I get the error :
Class 'Stripe\Stripe' not found
Note: In my host I don't have SSH. And I added files manually with FTP.
\Stripe\Stripe::setApiKey("sk_test_XXXXXX");
$token = $request->stripeToken;
$customer = \Stripe\Customer::create([
'email' => $client->email,
'source' => $token,
]);
As mentioned you have installed Stripe library manually and uploaded on server.
To use this library include init file.
require_once('/path/to/stripe-php/init.php');
ON next step set Api key, Make sure to use test api key for testing.
\Stripe\Stripe::setApiKey( "sk_test_XXXXXX");
Make sure to download latest stripe library from Githut repo
As i have seen mentioned in the comments:
Stripe needs to be installed using (preferably) composer.
This can be done with the command: composer require stripe after having SSHed into the right directory.
You then need to include the vendor/autoload.php that is generated by composer.
In your case where you cant run composer do the following:
Download stripe`s latest release manually from the github page: https://github.com/stripe/stripe-php/releases
Then you need to include the init.php file found in the downloaded stripe-php directory like this require_once('/path/to/stripe-php/init.php');
Ensure you are running at least PHP 5.4 (Note! This version has reached its end of life. Upgrade if possible to PHP 7.2). You also need the PHP extensions curl, json and mbstring.
After having used require_once('/path/to/stripe-php/init.php'); in the file the stripe code will be running in you can then set your API key using \Stripe\Stripe::setApiKey("sk_test_XXXXXX"); and then run your code like f.ex: $customer = \Stripe\Customer::create([
'email' => $client->email,
'source' => $token,
]);
`
Please use stripe library with the below code to resolve the error
$stripe_obj = new Stripe();
$stripe = $stripe_obj->setApiKey(env('STRIPE_SECRET'));

How to fix "Non-static method Spatie\Analytics\Analytics::fetchVisitorsAndPageViews() should not be called statically?"

When i put:
use Spatie\Analytics\Analytics;
It gives the error
'Non-static method should not be called statically'
But when I only put:
use Analytics;
I gives a white page on refresh or says
"The use statement with non-compound name 'Analytics' has no effect "
when starting.
I am using Laravel 5.5.4 and although it says the facade should be automatically setup, it wasn't working so I also added this manually to the // config/app.php:
'Analytics' => Spatie\Analytics\AnalyticsFacade::class,
But it still is not working.
from the package github. there was a solution
php artisan config:clear
but it did not work for me.
This package can be installed through Composer.
composer require spatie/laravel-analytics
In Laravel 5.5 and above the package will autoregister the service provider. In Laravel 5.4 you must install this service provider.
config/app.php
'providers' => [
...
Spatie\Analytics\AnalyticsServiceProvider::class,
...
];
In Laravel 5.5 and above the package will autoregister the facade. In Laravel 5.4 you must install the facade manually.
config/app.php
'aliases' => [
...
'Analytics' => Spatie\Analytics\AnalyticsFacade::class,
...
];
You want to use the facade to access the class, you will need to change:
use Spatie\Analytics\Analytics; to use Analytics;
Another way around just import this to your class:
use Spatie\Analytics\AnalyticsFacade as Analytics
It depends in what context you place the use statement.
In Laravel you also can use facades without having to import it with use.
The same class can be called by using \Analytics in your code call.
Example:
\Analytics::fetchMostVisitedPages(\Period::days(7));

Class 'GuzzleHttp\Client' not found on Laravel production shared server

I'm trying to retrieve data from an API using Guzzle. I followed the steps in Guzzle website, installed it using composer, added the route and the code in a controller.
I tried these two options:
$client = new Client([
// Base URI is used with relative requests
'base_uri' => 'https://jsonplaceholder.typicode.com/',
// You can set any number of default request options.
'timeout' => 2.0,
]);
and...
$client = new \GuzzleHttp\Client([
// Base URI is used with relative requests
'base_uri' => 'https://jsonplaceholder.typicode.com/',
// You can set any number of default request options.
'timeout' => 2.0,
]);
When running I got the error...
Class 'GuzzleHttp\Client' not found.
I have tried:
require( dirname( __FILE__ ) . '/../../../vendor/autoload.php');
use GuzzleHttp\Client;
In composer.json:
"require": {
"guzzlehttp/guzzle": "^6.3",
...
},
Also...
composer update
composer dump-autoload
php artisan config:clear
The project is on shared hosting; I noticed that there was no Guzzle folder inside the /vendor folder, so I uploaded via FTP. But still the same error.
I've tried everything I found in the forum on this topic; I'm running out of ideas, please any advice would be appreciated.
Thanks in advance for your valuable help.
If you can't run composer on shared hosting, you should upload also /vendor/composer directory (after local $ composer require guzzlehttp/guzzle).

Load config class in App\Libraries in Laravel 5.4

H Guys,
I have custom folder in App folder call libraries in laravel 5.2 version.In that libraries folder have a error.php file. I need load my custom config file to the error.php. I have try Config::get('errorreporter.active') & config('errorreporter.active') But these to not work. any one can help me please for resolve this issue
Move the file to the config folder and use the correct naming:
Config::get('[filename].[array_key]');
So if config/error.php has the following content:
<?php
return [
'active' => true
];
then the correct way of calling that value would be
Config::get('error.active')
or
config('error.active')

how to import Laravel 4.2 live project into locallhost

i am importing a live Laravel 4.2 Web application and setup it into my localhost for development.
in the Laravel 5 we usually find the .env file in the root dictionary but in Laravel 4.2 i couldn't be able to find .env and another component and their dictionaries are also different.
can anybody tell me how to import my laravel 4.2 web app into the local host step by step?
All of the configuration files for the Laravel framework are stored in the app/config directory 1. You have to set everything directly there or build an own .env.local.php file with default values like this:
<?php
//file: /.env.local.php
// return the configuration for the 'local' environment
return array(
'db_host' => '127.0.0.1',
'db_name' => 'DB_NAME', // specify database name
'db_user' => 'DB_USER', // specify database username
'db_pass' => 'DB_PASS', // specify database password
);

Resources