Using php session in laravel 5 seems impossible to me. But there is no limit to knowledge.
I got a project from somebody in which php session was used in a laravel project. The project is so huge that converting the php sessions to laravel session is a huge task.
But it seems that the php session supports to work on localhost i.e. wamp and the project seems bug free. But deploying on the server its a mess. The server is a linux server. i tried to replicate the setttings to wamp. But can't get it working.
Is there any minor chance of making the application working without going through the whole project.
Got a fix to it.
The solution was
Since the project was to large to change the whole code so i added a small piece of code in the AppServiceProvider
<?php
namespace App\Providers;
session_start();
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* #return void
*/
public function boot()
{
$this->composer();
}
/**
* Register any application services.
*
* #return void
*/
public function register()
{
}
public function composer(){
view()->share($_SESSION);
}
}
Which defined as a variable in the whole Laravel project as well as session variables to where ever required.
Even though this is not the right way to use session but it helps to fix the issue.
Related
I develop my Laravel applications using Windows with Laravel Homestead. In Laravel Homestead I am using PHP 8.0.21 and Laravel 9.23.
I deployed my project to a host without any errors. However, Laravel does not recognize the PHP class of Blade components, making it impossible to use the application.
It is as if the component were anonymous. I put a dd('hi') in the class construct and nothing happens.
I cleared all Laravel caches using artisan optimize:clear. I cleared all server caches. I checked access permissions. Nothing solved, still not being able to use the application.
In my local environment the application works, but in hosting it doesn't. I don't know what else to check as there is no error log.
The hosting PHP version is 8.0.20, I don't believe that's the reason for the problem.
Can you help me?
Component call
<x-admin.sidebar.sidebar-main />
Component
<div>
The only way to do great work is to love what you do. - Steve Jobs
</div>
Class Component
<?php
namespace App\View\Components\admin\sidebar;
use App\Models\Menu;
use Illuminate\View\Component;
class SidebarMain extends Component
{
/**
* Menus da área administrativa.
*
* #var array
*/
public array $menus;
/**
* Create a new component instance.
*
* #return void
*/
public function __construct()
{
dd('xxxxxxxxxxx');
}
/**
* Get the view / contents that represent the component.
*
* #return \Illuminate\Contracts\View\View|\Closure|string
*/
public function render()
{
return view('components.admin.sidebar.sidebar-main');
}
}
I have recently integrated Algolia with my laravel application using Laravel-Scout library. Whenever, I try to search to search any products using algolia, I get GuzzelHttp\Exception\Connection\Exception. Following is the screen output of the response. The same issue also appears when I sync my database with Algolia's server. I have doubled checked my Algolia credentials in my project and they match correctly. I am running this project in linux mint-18.04 LTS, using default laravel server (neither Apache nor Nginx) and MySQL server.
It can be solved in the following way, given that you have already added Scout to your project:
Create your own app\Scout\EngineManager.php:
<?php declare(strict_types = 1);
namespace App\Scout;
use Algolia\AlgoliaSearch\Config\SearchConfig;
use Algolia\AlgoliaSearch\SearchClient as Algolia;
use Algolia\AlgoliaSearch\Support\UserAgent;
use Laravel\Scout\EngineManager as BaseEngineManager;
use Laravel\Scout\Engines\AlgoliaEngine;
class EngineManager extends BaseEngineManager
{
/**
* Create an Algolia engine instance.
*
* #return \Laravel\Scout\Engines\AlgoliaEngine
*/
public function createAlgoliaDriver()
{
$this->ensureAlgoliaClientIsInstalled();
UserAgent::addCustomUserAgent('Laravel Scout', '7.0.0');
$config = SearchConfig::create(config('scout.algolia.id'), config('scout.algolia.secret'));
$config->setConnectTimeout(10);
$algolia = Algolia::createWithConfig($config);
return new AlgoliaEngine(
$algolia,
config('scout.soft_delete')
);
}
}
Create your own app\Scout\Searchable.php:
<?php declare(strict_types = 1);
namespace App\Scout;
use Laravel\Scout\Searchable as BaseSearchable;
trait Searchable
{
use BaseSearchable;
/**
* Get the Scout engine for the model.
*
* #return mixed
*/
public function searchableUsing()
{
return app(EngineManager::class)->engine();
}
}
Create your own app\Providers\ScoutServiceProvider.php:
<?php declare(strict_types = 1);
namespace App\Providers;
use App\Scout\EngineManager;
use Laravel\Scout\ScoutServiceProvider as BaseScoutServiceProvider;
class ScoutServiceProvider extends BaseScoutServiceProvider
{
/**
* Register the service provider.
*
* #return void
*/
public function register()
{
$this->app->singleton(EngineManager::class, function ($app) {
return new EngineManager($app);
});
parent::register();
}
}
Exclude the default scout package from the package discovery in your composer.json:
"extra": {
"laravel": {
"dont-discover": [
"laravel/scout"
]
}
},
Add your ScoutServiceProvider to the provider list in config/app.php.
Run composer dumpautoload.
Whenever adding the Searchable trait to a model, add your own trait to it instead of Scout's.
If you would like to make the timeout environment-dependent, it can be extracted to a config setting. Also please keep it in mind that the above is a bare minimum for getting the Searchable trait to work with a longer timeout, other classes may also need to be overridden for other features to work.
Algolia has default timeouts and this error pops when requests are over the default (I believe 2 seconds). You can check how long requests might be taking for you with: time host [ALGOLIA_ID].algolia.net. Unfortunately, Laravel Scout doesn't have the ability to override this and I've not found a good workaround.
I recently started using laravel so i'm a beginner, and right now i'm working on a small project which requires me use shortcodes(like the ones in wordpress).
So i searched for a little bit and found this package:
https://packagist.org/packages/webwizo/laravel-shortcodes
I ran the installation and usage the way it's written but i get the error : Class 'App\Providers\Shortcode' not found in the provider I have to make using the laravel make:provider command as specified in the package instructions, below is my exact usage and install code.
added this to the providers array :
/*
* shortcodes providers
*/
Webwizo\Shortcodes\ShortcodesServiceProvider::class,
App\Providers\ShortcodesServiceProvider::class,
Added this to aliases:
'Shortcode' => Webwizo\Shortcodes\Facades\Shortcode::class,
this is the content of my ShortcodesServiceProvider in app/providers:
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use App\Shortcodes\JobsForm;
class ShortcodesServiceProvider extends ServiceProvider
{
/**
Bootstrap the application services.
*
#return void
*/
public function boot()
{
//
}
/**
Register the application services.
*
#return void
*/
public function register()
{
Shortcode::register('jobs', JobsForm::class);
}
}
I use laravel 5.4 so that might be an issue.
The thing is the class obviously exists, it gives the Shortcodes class not found error because I think it searches for it in the app/providers/ShortcodesServiceProvider file, and obviously it's not there it's in the vendor file.
Is there something I'm missing i've checked and double checked, I can't seem to get this thing to work.
It shoould work considering it has an alias defined right ?
I used it in the view like this:
return view('quarx-frontend::pages.' . $page->template)->with('page', $page)->withShortcodes();
Thanks for taking the time to read this any help would be much appreciated.
If you need any more info I'll be glad to supply it.
p.s. sorry for bad english ,not a native speaker :P
It searches for Shortcode in the App\Providers; namespace and not in the root namespace where the Facade is defined.
You can fix this in App\Providers\ShortcodesServiceProvider.php by either doing:
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use App\Shortcodes\JobsForm;
use Shortcode;
class ShortcodesServiceProvider extends ServiceProvider
{
Or use \Shortcode
/**
* Register the application services.
*
* #return void
*/
public function register()
{
\Shortcode::register('jobs', JobsForm::class);
}
I would recommend the first option.
Currently I'm trying to implement the Doctrine CouchDB Bundle in a Silex Application. At one point the complete site ends in a 500/internal server error in my local dev stack. Setting breakpoints and debugging them with XDebug and PHPStorm hasn't brought me to any result so far. Apache Error logs are empty, PHP error logs as well and error_reporting(-1); still doesn't give any output. Probably the problem is the reflection class usage in there.
Everything works well, until I try to use CouchDB Annotations from
use Doctrine\ODM\CouchDB\Mapping\Annotations as CouchDB;
and use them in my Document
/** #CouchDB\Document */
class Station
{
/**
* #Index
* #Id
*/
private $id;
If I remove the CouchDB\ above, everything works. But if I remove it, and use #Id(strategy="ASSIGNED"), I run into the exact same problem.
I tried to register the Annotations in several ways without luck. #Ocramius suggested in chat that I should simply override the Autoloader, which worked well with getting beyond some other problems, but not for that case (just adding it here in case someone else needs it).
AnnotationRegistry::registerLoader( function( $className ) {
return class_exists( $className );
} );
Try to use
/**
* #CouchDB\Index
* #CouchDB\Id
*/
instead of
/**
* #Index
* #Id
*/
You can also solve this by adding this line before you run your Silex Application (probably in index.php).
AnnotationRegistry::registerLoader('class_exists');
I'm playing around with packages and I'm able to my code to work (in my controllers) when I do this:
App::make('Assets')->js('bla');
Now I want to set up a static facade so I can do this:
Assets::js('bla');
for this and I'm getting errors. I've been following this blog entry and haven't had any trouble up to this point. But now I'm stuck with a " Call to undefined method" error.
I'm not sure what code you'd need to see, so here's everything: https://github.com/JoeCianflone/msl/tree/jc-working
Specifically here is my workbench: https://github.com/JoeCianflone/msl/tree/jc-working/workbench/Joecianflone/Assets
And here is the controller where I was messing around with it: https://github.com/JoeCianflone/msl/blob/jc-working/app/controllers/HomeController.php
Any help greatly appreciated.
Looks like it was an issue with namespacing, I got it working by changing this:
<?php namespace Joecianflone\Assets\Facades;
use Illuminate\Support\Facades\Facade;
class Assets extends Facade {
/**
* Get the registered name of the component.
*
* #return string
*/
protected static function getFacadeAccessor() { return 'Assets'; }
}
to this:
class Assets extends \Illuminate\Support\Facades\Facade {
/**
* Get the registered name of the component.
*
* #return string
*/
protected static function getFacadeAccessor() { return 'Joecianflone\Assets\Assets'; }
}
What I'm not sure about is why the code from the tutorial worked but mine didn't. I must have skipped a step.
Just a sidenote, if you plan to share your code with the communuty (please do) i encourage you to use 5.3 syntax. Laravel requirements is 5.3 so dont use 5.4 in your package.