I want to add telescope into my laravel 8 app, but having in .env
APP_ENV=local
TELESCOPE_ENABLED=true
and reading at site :
https://laravel.com/docs/8.x/telescope
The Telescope dashboard may be accessed at the /telescope route. By default, you will only be able to access this dashboard in the local environment.
on url
http://local-tads.com/telescope
I got 404 error, where http://local-tads.com - is local hosting of my app
In app/Providers/AppServiceProvider.php file I added lines :
<?php
namespace App\Providers;
class AppServiceProvider extends ServiceProvider
...
if ($this->app->environment('local')) {
$this->app->register(\Laravel\Telescope\TelescopeServiceProvider::class);
\Event::listen(
[
TransactionBeginning::class,
],
function ($event) {
...
I have unmodified vendor/laravel/telescope/config/telescope.php file.
Have I to add route in routes/web.php and in which way ?
How to get access to telescope dashboard ?
UPDATED BLOCK :
I run both commands :
php artisan telescope:install
php artisan migrate
But I did not find config/telescope.php, so I copied it from /vendor/ subdirectory
Running command
php artisan route:list
has no any “telescope” entry.
In file app/Providers/AppServiceProvider.php I added lines with telescope :
<?php
namespace App\Providers;
use App\Library\Services\AdminCategoryCrud;
//use App\Providers\TelescopeServiceProvider;
use Illuminate\Database\Events\TransactionBeginning;
use Illuminate\Database\Events\TransactionCommitted;
use Illuminate\Database\Events\TransactionRolledBack;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Blade;
use Laravel\Telescope\IncomingEntry;
use Laravel\Telescope\Telescope;
use Laravel\Telescope\TelescopeServiceProvider;
class AppServiceProvider extends ServiceProvider
{
public function register()
{
if ($this->app->environment('local')) {
$this->app->register(\Laravel\Telescope\TelescopeServiceProvider::class);
$this->app->register(TelescopeServiceProvider::class);
}
Not sure if all is correct?
in env I have :
APP_ENV=local
TELESCOPE_ENABLED=true
and in composer.json I added line :
"extra": {
"laravel": {
"dont-discover": [
"laravel/telescope"
]
}
},
and updated composer
But http://local-tads.com/telescope - still raise 404 error...
Thanks in advance!
I have this problem but I attention Laravel Documentation I watch this code and run them:
telescope:install
, you should remove the
TelescopeServiceProvider
service provider registration from your application's
config/app.php
configuration file. Instead, manually register Telescope's service providers in the
register
method of your
App\Providers\AppServiceProvider
class.
A potential answer to your problem could be removing the telescope package from the dont-discover array. So your new extra section would be like this one:
"extra": {
"laravel": {
"dont-discover": []
}
}
Also, don't forget to dump your autoload by running composer dump-autoload in your project folder. I hope this helps you :D
For more information please check this issue on the github repository.
Related
I've tried now some different approaches and read articles here and elsewhere but i can't figure out what i'm doing wrong.
I'm developing a package and I want it to be installed via symlink in a different project to develop both parts simultaneously without the need of updating the dependencies over and over again.
The thing I cant get to work is the autoloading.
Here is my setup:
Project composer.json
{
"repositories": [
{
"type": "path",
"url": "../../FormTableComponent",
"options": {
"symlink": true
}
}
],
"require": {
[...]
"bluechord/formtablecomponent": "#dev"
}
}
FormtableComponent Folder Structure
FormTableComponent/
src/
| Container.php
composer.json
FormtableComponent composer.json
{
"name": "bluechord/formtablecomponent",
"description": "...",
"autoload": {
"psr-4": {
"BlueChord\\FormTableComponent\\": "src/"
}
},
"require" : {
[...]
}
}
FormtableComponent Container.php
<?php
/**
* FormTable Container. The Container Class that registers all Parts of the
* Component.
*/
namespace BlueChord\FormTableComponent;
class Container {
function __construct() {
}
}
When I try to use the class and instantiate it I get
Uncaught Error: Class 'BlueChord\FormTableComponent\Container' not found
Thanks for your help!
ADDITIONAL INFO:
A simple Test.php which reproduces the error inside the project
<?php
require_once 'bin/vendor/autoload.php';
echo "BCOSP Test";
use DebugBar\StandardDebugBar;
use BlueChord\FormTableComponent\Container;
$debugbar = new StandardDebugBar(); --> WORKS
echo StandardDebugBar::class ."\n";
$container = new Container(); --> ERROR
echo Container::class . "\n";
Composer
The vendor/composer/autoload_psr4.php does NOT contain any array key for my package.
If I run composer dump-autoload inside my main project nothing changes.
If I run composer dump-autoload inside my package it creates the correct autoload_psr4.php
I am using Laravel 5.8 and I created a custom class named StatusLib.php in the app/library folder.
StatusLib.php
namespace App\library;
class StatusLib
{
CONST SUCCESS = '100';
CONST SUCCESSWITHMESSAGE = '101';
}
I can call this status .
StatusLib::SUCCESS
When I add this following use code in the controller.
use app\library\StatusLib;
How can I add this StatusLib class in autoload and access from anywhere in the project?
Namespaces are case-sensitive.
In your StatusLib class you have App\library;, however, in your controller you've used app\library -- these are not the same.
Change your use statement in your controller to be:
use App\library\StatusLib;
You may also need to run:
composer dumpautoload
Just FYI, Laravel comes with the app directory already set up for autoloading.
In your composer.json file, after the classmap array, add a psr-0:
"autoload" :{
"classmap": [
...
],
"psr-0": {
"library": "app/"
}
}
Run composer dump-autoload.
Hope it helps.
where do you want to use it?
it will be automatically autoloaded because app folder is loaded in composer.json
here:
"autoload": {
"psr-4": {
"App\\": "app/"
},
},
My question is very simple but I have no clue: I have always been working with java and eclipse or C# until now so it's a "new world" :)
How can I debug my laravel code?
I am using laravel and vuejs. I start my server with laragon, and I use VScode. I have tried starting it from VScode (added xdebug dll in laragon) but it doesn't give me more info, and I don't manage to debug anything using breakpoints:
{
"name": "Launch localhost",
"type": "chrome",
"request": "launch",
"url": "http://127.0.0.1/",
"webRoot": "C://laragon//www//projet"
},
{
"name": "Launch index.php",
"type": "chrome",
"request": "launch",
"file": "C://laragon//www//projet//index.php"
},
When I get an error with sql, all I get is
app.js:651 Uncaught (in promise) Error: Request failed with status code 500
at createError (app.js:651)
at settle (app.js:814)
at XMLHttpRequest.handleLoad (app.js:184)
How can I see my SQL request and get the "real error"?
And how can I properly debug?
Thanks a lot in advance.
You have multiple options to achieve the SQL logging:
1.Use query listener by registering it in service provider (boot method as follow)
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;
use DB;
use Log;
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
Schema::defaultStringLength(191);
DB::listen(function($query) {
Log::info(
$query->sql,
$query->bindings,
$query->time
);
});
}
}
Use Query logging please refer to https://laravel.com/docs/5.0/database#query-logging
Use laravel debugger package please refer to https://github.com/barryvdh/laravel-debugbar
You can debug php with xdebug but i would still prefer any option among above 3.
You can use Laravel Debugbar to see the real time queries. It provides many other useful information for debugging purpose. Please check this link https://github.com/barryvdh/laravel-debugbar
Also try to log the collection into SQL using query listener by registering it inside service provider:
<?php
namespace App\Providers;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Log;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* #return void
*/
public function boot()
{
DB::listen(function ($query) {
// $query->sql
// $query->bindings
// $query->time
Log::useDailyFiles(storage_path().'/logs/query_log.log');
$query = $query->sql;
Log::info($query);
});
}
/**
* Register the service provider.
*
* #return void
*/
public function register()
{
//
}
}
I am using Laravel 5.3 and for testing purpose, I have created a folder called "Helpers" is "app" folder. In "Helpers" folder, there is a file named credentials.php where I will declare some strings then I will use it later. Credentials.php looks like
`
<?php
namespace App\Helpers;
class Credential
{
}
`
In the 'tests' folder there is folder called 'links' and in this folder there is file called something.php and it looks like
<?php
use App\Helpers\Credential;
class something extends TestCase
{
}
and its working correctly...Problem arising when I am trying to put the "helpers" folder from "app" to "tests" folder. I dont want to put the "Helper" folder in "app" directory. I have changed namespace and other things, nothing works. I am new to laravel and seeking your help and suggestion.
Update Composer.json and add files key in autoload section.
"autoload": {
"files": [
"tests/helpers.php"
],
"classmap": [
"database/seeds",
"database/factories"
],
"psr-4": {
"App\\": "app/"
}
},
After Adding this, run the following command.
composer dump-autoload
When running the example code on the laravel docs php artisan make:request StoreBlogPostRequest to create a new validation controller, I get the following error
[RuntimeException]
Unable to detect application namespace.
I'm not sure what's wrong, I've done some searching, but nothing really explains this error. Any ideas?
In Laravel 5, an "application" is a collection of PHP files under a single namespace, stored in the folder app/
By default, and in most of the Laravel 5 sample code from the docs, this namespace is App\. For example, one controller in your application might look like this.
namespace App\Http\Controller;
class MyController
{
//...
}
When Laravel generates code (i.e. when you use the make:request command), it needs to know what this application namespace is (it's possible to change the namespace with the artisan app:name command). For some reason, in your system, Laravel 5 can't detect the namespace.
If you look at the section of Laravel 5 core code that detects the namespace
#File: vendor/laravel/framework/src/Illuminate/Console/AppNamespaceDetectorTrait.php
protected function getAppNamespace()
{
$composer = json_decode(file_get_contents(base_path().'/composer.json'), true);
foreach ((array) data_get($composer, 'autoload.psr-4') as $namespace => $path)
{
foreach ((array) $path as $pathChoice)
{
if (realpath(app_path()) == realpath(base_path().'/'.$pathChoice)) return $namespace;
}
}
throw new RuntimeException("Unable to detect application namespace.");
}
You'll see that Laravel detects the namespace by looking at your composer.json file, and looking for thefirst valid psr-4 namespace.
My guess is your composer.json file is missing the namespace
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
}
},
Add that back in, and you'll be good to go.
Usually, this error can be mapped to syntax issues or errors in composer.json file. Check for any trailing commas or Auto load issue. For e.g.
"require-dev": {
"barryvdh/laravel-debugbar": "^3.5",
"phpunit/phpunit": "^7.5",
},
This should be..
"require-dev": {
"barryvdh/laravel-debugbar": "^3.5",
"phpunit/phpunit": "^7.5"
},
See no trailing commas at the end of "phpunit/phpunit": "^7.5"