I already install yajra package but it still show me error
my controller and i also used namespace
use Datatables;
return Datatables()->of($data)->make(true);
my providers
Yajra\Datatables\DatatablesServiceProvider::class,
'aliases'
'Datatables'=>Yajra\Datatables\DatatablesServiceProvider::class,
You have to call it with a helper and you don't have to include it. You accessed the class of datatables, not the helper. Do it like this.
return datatables()->of($data)->make(true);
Yajra namespace is Yajra\DataTables. so you need to call it as below.
use Yajra\DataTables\Datatables;
or if you want to call only use Datatables then you need to set providers and alias.
config/app.php
.....
'providers' => [
....
Yajra\DataTables\DataTablesServiceProvider::class,
]
'aliases' => [
....
'DataTables' => Yajra\DataTables\Facades\DataTables::class,
]
.....
And then you can use simply
use DataTables;
Related
I want to implement a search option on my Laravel application, but had this error:Class 'Illuminate\Support\Facades\Input' not found, I have tried to add this row at config/app like this:
'aliases' => [
....
'Input' => Illuminate\Support\Facades\Input::class,
Also at Controller I have added those rows:
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
At Route I have added
Route::any('/search',function(){
$image_tmp = $request->image;
$fileName = time() . '.'.$image_tmp->clientExtension();
$q = Input::get ( 'q' );
$book = Book::where('title','LIKE','%'.$q.'%')->get();
if(count($book) > 0)
return view('home')->withDetails($book)->withQuery ( $q );
else return view ('home')->withMessage('No Details found. Try to search again!');
});
But still it doesn't work.
Try this
config/app.php
use Request instead of Input
'aliases' => [
....
'Input' => Illuminate\Support\Facades\Request::class,
And your controller
use Illuminate\Http\Request;
and remove use Illuminate\Support\Facades\Input; top of your code
you have used the class in the controller but your route is never going to one as you are using a closure. so add Input class in your web.php file. at the top of your web.php file add
<?php
use Illuminate\Support\Facades\Input;
if you are using any latest version of laravel, the Input class no longer exists. so use Request class instead
<?php
use Illuminate\Http\Request;
you can use request() global helper too to get request values.
however i would suggest you to not use closure, rather use controller for logical operation.
Inside a Laravel Package EspacePartenaire I need to share some data between all its views using View Composer.
Ths boot() method inside EspacePartenaireServiceProvider containes the following:
$this->loadViewsFrom(__DIR__ . '/views', 'espace-partenaire');
View::composer('*', CurrentPartenaireComposer::class);
But I don't want to share data in all the views. I need it only in the views that are located in the view folder of the Package /packages/EspacePartenaire/src/views
When I change arguments of the composer function like below:
View::composer('espace-partenaire', CurrentPartenaireComposer::class);
or
View::composer('espace-partenaire::*', CurrentPartenaireComposer::class);
I had the error that my variables are undefined.
How can I achieve this?
EDIT:
This is the Package routes file:
Route::group([
'middleware' => ['web', 'auth'],
'namespace' => 'App\Services\EspacePartenaire\Http\Controllers',
'prefix' => 'espace-partenaire'
], function(){
...
Route::get('/', 'EspacePartenaire#index');
...
});
Based on your packages structure i think the following approach could maybe work, it seems first parameter is the path and you can do * as a wildcard.
View::composer('*espace-partenaire*', CurrentPartenaireComposer::class);
Hi I'm having a problem about my codes in my PagesController.
I'm wondering what is the error about the notification it says undefined variable but it has the same codes in countOrder and countProduct and those two are working just only the notification
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\CustomerOrder;
use App\Product;
use App\Notification;
use DB;
class PagesController extends Controller
{
public function count() {
$countOrder = CustomerOrder::count();
$countProduct = Product::count();
$notification = Notification::count();
return view('/adminIndex',['customer_orders' => $countOrder],['products' => $countProduct],['notifications' => $notification]);
}
}
There may be a few issues here.
Firstly, when passing data to a view, you must use one array (rather than several):
return view('/adminIndex', ['customer_orders' => $countOrder, 'products' => $countProduct, 'notifications' => $notification]);
Secondly, the first argument of the view() helper expects the view file (found in the /resources/views folder). So if the file is adminIndex.blade.php use:
return view('adminIndex', ['customer_orders' => $countOrder, 'products' => $countProduct, 'notifications' => $notification]);
Hope this helps.
I'm quite new to Laravel and Lumen, so my question may be a little simple, but I couldn't find any useful answer yet.
Lumen version is 5.1.
So I tried to create a data repository supported by a cache. Firstly I want to use FileStore, then I want to move to some more appropriate.
I tried to inject Cache repository like this:
<?php
namespace App\Repositories;
use Illuminate\Cache\Repository;
class DataRepository
{
private $cache;
public function __construct(Repository $cache)
{
$this->cache = $cache;
}
}
It seemed pretty simple to me. But when I try to use this repo in my controller, and tried to inject this repo into it, during instantiation I get the following error:
BindingResolutionException in Container.php line 749:
Target [Illuminate\Contracts\Cache\Store] is not instantiable.
I guessed the repository cannot find the matching and useable store implementation. When I tried to bind the Store to \Illumante\Cache\FileStore like this:
$this->app->bind(\Illuminate\Contracts\Cache\Store::class, \Illuminate\Cache\FileStore::class);
I got a new kind of error:
Unresolvable dependency resolving [Parameter #1 [ <required> $directory ]] in class Illuminate\Cache\FileStore
I guess I have a more complicated config issue, so I didn't want to walk through the dependency tree.
In my .env I have these:
CACHE_DRIVER=file and SESSION_DRIVER=file
In Lumen I explicitly enabled the facades, the DotEnv (and the eloquent also for my data repositories).
Dotenv::load(__DIR__.'/../');
$app = new Laravel\Lumen\Application(
realpath(__DIR__.'/../')
);
$app->withFacades();
$app->withEloquent();
I tried to add a cache.php configuration. In the bootstrap/app.php I added $app->configure('cache'); to use it with the following configs:
<?php
return [
'default' => env('CACHE_DRIVER', 'file'),
'stores' => [
'file' => [
'driver' => 'file',
'path' => storage_path('framework/cache'),
],
],
];
Could you help me, how can I bootstrap the Cache properly?
Answer
The cache implementation in Lumen is registered as:
Illuminate\Contracts\Cache\Repository
Not
Illuminate\Cache\Repository
So you may change your code to:
<?php
namespace App\Repositories;
use Illuminate\Contracts\Cache\Repository;
class DataRepository
{
private $cache;
public function __construct(Repository $cache)
{
$this->cache = $cache;
}
}
P.S You don't need to configure cache, since Lumen will configure any cache configuration automatically.
Tricks
But if you still want to use Illuminate\Cache\Repository, you may bind it first in your ServiceProvider or bootstrap/app.php file:
use Illuminate\Cache\Repository as CacheImplementation;
use Illuminate\Contracts\Cache\Repository as CacheContract;
$app->singleton(CacheImplementation::class, CacheContract::class);
Im trying to use SSH:: command in my controller but I'm facing error:
Class 'SSH' not found
my controller:
namespace App\Http\Controllers;
use Session;
use DB;
use SSH;
and call action:
SSH::run(
array(
'cd /var/www/laravel',
'node accept.js '
)
);
so where the problem could be?
You need to follow the installation guide of Laravel SSH package:
1. Install it via Composer:
Add this to your composer.json:
"require": {
"laravelcollective/remote": "~5.0"
}
Then run composer update.
2. Add new provider to the providers array of config/app.php:
'providers' => [
// ...
'Collective\Remote\RemoteServiceProvider',
// ...
],
3. Add two class aliases to the aliases array of config/app.php:
'aliases' => [
// ...
'SSH' => 'Collective\Remote\RemoteFacade',
// ...
],