I was install Laravel Scout with next instruction, but I have a problem :(
1) Used command composer require laravel/scout
2) Added into providers section 'Laravel\Scout\ScoutServiceProvider::class,'
3) Used command php artisan vendor:publish --provider="Laravel\Scout\ScoutServiceProvider"
4) Added Extends
Laravel\Scout\Searchable
use Searchable;
5) Used command composer require algolia/algoliasearch-client-php
6) Model has code:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Laravel\Scout\Searchable;
use DB;
class Product extends Model
{
use Searchable;
protected $table = 'products';
public static function getProductsBySearch($search)
{
// Список найденных продуктов
$searchProducts = Product::search('Test')
->get()
->all();
return $searchProducts;
}
}
But Have error:
AlgoliaSearch requires an applicationID
What is Algolia? How will solve it's problem?
You need to configure it with your Algolia credentials. It is a third party service providing the full text search functionality.
From the docs:
When using the Algolia driver, you should configure your Algolia id and secret credentials in your config/scout.php configuration file.
You can also use algolia dedicated library for laravel.
Laravel-scout-extended
There is cool feature like php artisan scout:status to see your local DB / and Index in algolia.
If you need more information as an advice you should watch this video :
Scout-Extended
I hope it will help you.
Related
I can't use binance api in laravel
I installed Php binance api from composer require "jaggedsoft/php-binance-api #dev" but examples not working in laravel.I had some errors when I tried.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
require '../vendor/autoload.php';
class BinanceController extends Controller
{
public function list()
{
$api = new Binance\API();
$key = "----";
$secret = "---";
$api = new Binance\API($key, $secret);
$price = $api->price("BNBBTC");
return $price;
}
}
When I runned the route I got this error:
Symfony\Component\Debug\Exception\FatalThrowableError Class
'App\Http\Controllers\Binance\API' not found
You're not importing Binance\API correctly. Laravel believes the Binance\Api class is located in the App\Http\Controllers\Binance namespace. Which it is not.
Try $api = new \Binance\API();
Or put it in your use cases.
use Binance\API
I also found an old wrapper which you may be able to import if there hasn't been any changes to Binance since but I highly doubt it. Since your case is specific to Laravel, look for a Binance wrapper for Laravel specifically. Here may contain some useful information on how to use non-laravel packages, with laravel
I'm trying to access the User model in a utility I built that will eventually send emails out, this is being triggered with by cron, and I'm using php artisan schedule:run to test it. Below is the utility I'm starting to build out, and currently when test it I am getting 'I was triggered'. This is being triggered by a registered console command. Thats all working.
<?php
namespace App\Utility;
use Log;
use Mail;
use App\User;
class ReferralProgramUtility
{
static public function test()
{
LOG::info("I was triggered");
}
}
However, when I change this to pull in the User model....
<?php
namespace App\Utility;
use Log;
use Mail;
use App\User;
class ReferralProgramUtility
{
static public function test()
{
$user = User::all();
LOG::info($user);
}
}
I get the following error....
Trying to get property of non-object in /var/www/html/appname/app/User.php:32
I'm using another utility that has a similar configuration and uses the User model and this work fine, the only difference is that this is on is being triggered by task scheduler. Not sure what is causing this, and I'm fairly new to Laravel so any tips or recommendation would be hugely appreciated. Thanks, in advance.
I'm using VisualPHPUnit as a GUI for my unit tests and I want to add it to my Laravel project.
I read this guide but it's obsolete being from 2015. There's no bootstrap.php file in config directory and there are no test_directories and bootstraps variables (I ran grep -rn . -e test_directories is Laravel directory).
Any idea what I can do to be able to add tests with artisan so they are working in VPU? Because Laravel test needs to extend Illuminate\Foundation\Testing\TestCase and VPU test needs to extend \PHPUnit_Framework_TestCase and I can't get it running. Either I don't see the test in VPU when I use Laravel's extend or I can't use Laravel's functions like visit when I use VPU's extend.
Edit:
Here's my PermissionTest.php:
<?php
namespace Visualphpunit\Test;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class PermissionTest extends \PHPUnit_Framework_TestCase
{
protected $baseUrl = 'http://localhost/laravel/public';
public function testExample()
{
$this->visit('/')->see('Logowanie');
}
public function createApplication()
{
$app = require __DIR__.'/../../bootstrap/app.php';
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
return $app;
}
}
...for which I get this error: Fatal error: Class 'Visualphpunit\Test\Illuminate\Foundation\Testing\TestCase not found in .../laravel/VisualPHPUnit-master/tests/PermissionTest.php on line 10
Is there a way to prevent using 'use' for everything. In Laravel 4 I never used 'use' and everything just worked. I'm now finding out I have to include everything, even 'DB' use DB. This is extremely frustrating and time consuming looking all this up.
My question is, is there an easier way to include everything?
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Customer;
use DB;
class HomeController extends Controller {
}
?>
Thanks
Not really -- this is the Brave New Namespaced world of PHP 5.3+. Your class file above lives in the App\Http\Controllers namespace, which means when you type something like
$object = new SomeClass;
PHP will assume you mean the class App\Http\Controllers\SomeClass.
You'll either, as you complained about, need to use use, or you'll need to use the full classname (with a leading \ to let PHP know to start from the global namespace) whenever you want to use a class
class HomeController extends Controller {
public function someFunction()
{
$result = \DB::query(...);
$customer = new \App\Models\Customer;
//etc...
}
}
This is question is old but I found you can do this based on information from a tutorial by Tejas Jasani: http://www.theappguruz.com/blog/upgrading-from-laravel-4-2-to-5-in-web
Here are the key steps:
1 - Add the app/Http/Controllers directory to the "autoload" classmap directive of your composer.json file.
"autoload": {
"classmap": [
"database",
"app/Http/Controllers"
],
2 - Remove the namespace from the abstract app/Http/Controllers/Controller.php base class.
3 - In app/Providers/RouteServiceProvider.php file, set the namespace property to null
protected $namespace = null;
4 - Run "composer dump-autoload" from the command line.
I'm new to Laravel and what I want to accomplish:
One laravel installation for multiple sites
Have some functions shared amongst all my sites, for instance User handling, while other functionality will be unique to a specific site
I want to pretty much have a wide variety of different sites under one installation, so I then can build an admin view where I can manage all sites.
How would I go about doing this? I have a fresh Laravel 4.2 installation.
You can have a look at the package rbewley4/multi-app-laravel on Github. Another hint can be found at this answer on StackOverflow
1. Create ConfigServiceProvider in app\Providers folder and set code:
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Request;
class ConfigServiceProvider extends ServiceProvider {
public function register() {
$template = $_SERVER["SERVER_NAME"];
$config = app('config');
$config->set('template', $template);
}
}
2. Create TemplateServiceProvider in app\Providers folder and set code:
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\View\FileViewFinder;
use Illuminate\View\ViewServiceProvider;
class TemplateServiceProvider extends ViewServiceProvider {
public function registerViewFinder() {
$this->app->bind('view.finder', function ($app) {
$template = $app['config']['template'];
if(file_Exists(realpath(base_path('themes/'.$template.'/views')))){
$paths = [realpath(base_path('themes/'.$template.'/views'))];
}else{
$paths = $app['config']['view.paths'];
}
return new FileViewFinder($app['files'], $paths);
});
}
}
3. Set providers in config/app.php :
App\Providers\ConfigServiceProvider::class,
App\Providers\TemplateServiceProvider::class,
4. Create your template forders > themes/{your_domain_name}/views