I want to use Logto log ,it works in controller,but it doesn't work in application(vendor/laravel/framework/src/Illuminate/Foundation/Application.php)
this is my code:
<?php
namespace Illuminate\Foundation;
use Log;
use Closure;
use RuntimeException;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Illuminate\Http\Request;
use Illuminate\Container\Container;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\ServiceProvider;
use Illuminate\Events\EventServiceProvider;
use Illuminate\Routing\RoutingServiceProvider;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Illuminate\Contracts\Foundation\Application as ApplicationContract;
class Application extends Container implements ApplicationContract, HttpKernelInterface
{
public function make($abstract, array $parameters = [])
{
$abstract = $this->getAlias($abstract);
if (isset($this->deferredServices[$abstract])) {
$this->loadDeferredProvider($abstract);
}
Log::info('test info '); // 698 line
return parent::make($abstract, $parameters);
}
I catch the error when I up the artisan serve:
php artisan serve
Fatal error: Class 'Log' not found in vendor/laravel/framework/src/Illuminate/Foundation/Application. php on line 698
Related
Route::get('/biller-
info','MyDomain\Http\Controllers\BillPaymentController#getBillerInfo');
All other routes for api are created like this.
Getting exception Target class [Mydomain\Http\Controllers\BillPaymentController] does not exist.
guzzlehttps is installed.
route - 127.0.0.1/biller-info
path - api > packages > mydomain-shop > src > Http > Controllers > BillPaymentController.php
BillPaymentController.php
<?php
namespace MyDomain\Http\Controllers;
use Exception;
use Illuminate\Http\Request;
use MyDomain\Enums\Permission;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use MyDomain\Exceptions\MyDomainException;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Http;
class BillPaymentController extends CoreController
{
public function getBillerInfo()
{
$response = Http::get('https://reqres.in/api/products/3');
dd($response->collect());
}
}
Loading configuration files and clearing cache did the TRICK!!
composer dump-autoload
php artisan route:clear
I used paginate to display the database data but got the following error
App\Repositories\AdminRepository::getAllAdmins(): Return value must be of type Illuminate\Pagination\Paginator, Illuminate\Pagination\LengthAwarePaginator returned
What namespace should I use to fix it?
This is my AdminRepository.php
<?php
namespace App\Repositories;
use App\Repositories\Interfaces\AdminRepositoryInterface as AdminRepositoryInterface;
use Illuminate\Database\QueryException;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\Log;
use App\Models\Admin;
use Illuminate\Support\Facades\Hash;
use App\Http\Requests\EditPassword;
use Illuminate\Contracts\View\View;
use App\Http\Requests\CreateAdmin;
use App\Http\Requests\DeleteAdmin;
use App\Http\Requests\EditAdmin;
use App\Services\AdminService;
use Illuminate\Http\Request;
class AdminRepository implements AdminRepositoryInterface
{
public function getAllAdmins(int $count):Illuminate\Pagination\AbstractPaginator
{
return Admin::paginate($count);
}
This is my AdminRepositoryInterface.php
namespace App\Repositories\Interfaces;
use App\Models\Admin;
use Illuminate\Http\RedirectResponse;
interface AdminRepositoryInterface
{
public function getAllAdmins(int $count):Illuminate\Pagination\AbstractPaginator;
The result of the getAllAdmins() function is a type of LengthAwarePaginator because the Laravel paginate function return that type and your function return it. so, you should change the return type to Illuminate\Pagination\LengthAwarePaginator not Paginator.
use Illuminate\Pagination\LengthAwarePaginator;
...
public function getAllAdmins(int $count): LengthAwarePaginator
{
return Admin::paginate($count);
}
I use macros to customize JSON response:
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Response;
use Illuminate\Support\ServiceProvider;
class ResponseMacroServiceProvider extends ServiceProvider
{
public function boot()
{
Response::macro('caps', function ($value) {
return Response::make(strtoupper($value));
});
}
}
After I have registered ResponseMacroServiceProvider in app.php in section providers.
Then in controller I call macros response:
return response()->caps('foo');
It says messages:
Method Illuminate\Routing\ResponseFactory::caps does not exist.
You can try php artisan optimize:clear to clean the cache files.
It also might be helpful to add a dd(booted) at the beginning of your boot method to see if the provider is called or not
I am trying to make a notification system in my project.
These are the steps i have done:
1-php artisan notifications:table
2-php artisan migrate
3-php artisan make:notification AddPost
In my AddPost.php file i wrote this code:
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
class AddPost extends Notification
{
use Queueable;
protected $post;
public function __construct(Post $post)
{
$this->post=$post;
}
public function via($notifiable)
{
return ['database'];
}
public function toArray($notifiable)
{
return [
'data'=>'We have a new notification '.$this->post->title ."Added By" .auth()->user()->name
];
}
}
In my controller I am trying to save the data in a table and every thing was perfect.
This is my code in my controller:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Post;
use App\User;
//use App\Notifications\Compose;
use Illuminate\Notifications\Notification;
use DB;
use Route;
class PostNot extends Controller
{
public function index(){
$posts =DB::table('_notification')->get();
$users =DB::table('users')->get();
return view('pages.chat',compact('posts','users'));
}
public function create(){
return view('pages.chat');
}
public function store(Request $request){
$post=new Post();
//dd($request->all());
$post->title=$request->title;
$post->description=$request->description;
$post->view=0;
if ($post->save())
{
$user=User::all();
Notification::send($user,new AddPost($post));
}
return redirect()->route('chat');
}
}
Everything was good until I changed this code:
$post->save();
to this :
if ($post->save())
{
$user=User::all();
Notification::send($user,new AddPost($post));
}
It started to show an error which is:
FatalThrowableError in PostNot.php line 41: Call to undefined method
Illuminate\Notifications\Notification::send()
How can i fix this one please??
Thanks.
Instead of:
use Illuminate\Notifications\Notification;
you should use
use Notification;
Now you are using Illuminate\Notifications\Notification and it doesn't have send method and Notification facade uses Illuminate\Notifications\ChannelManager which has send method.
Using this
use Illuminate\Support\Facades\Notification;
instead of this
use Illuminate\Notifications\Notification;
solved the problem for me.
Hope this helps someone.
using this is better
use Notification
Instead of
use Illuminate\Support\Facades\Notification
this makes the send() not accessible [#Notification Databse]
I want to add data to the database after a successful validation,but i get this error.'
FatalThrowableError in AboutController.php line 51:
Class 'App\About' not found.
My Controller
<?php
namespace App\Http\Controllers;
use App\About;
use Illuminate\Http\Request;
use App\Http\Requests;
class AboutController extends Controller
{
public function store(Request $request)
{
//
$about = $request->about;
$validation = \Validator::make($about, About::$rules);
if($validation->passes())
{
About::create($about);
return route('about/admin')->compact(about);
}
}
my Model
<?php
namespace App\Http\Controllers;
use Illuminate\Database\Eloquent\Model;
class About extends Model
{
//
protected $guarded = array('id');
protected $fillable = array('about');
public static $rules = array('about' => 'required|5');
}
location of controllers and Model:
App\Http\Controllers\AboutController
App\About
I have tried to run
php artisan cache:clear
php artisan clear-compiled
composer dump-autoload
I'm stuck can anyone tell me what is causing this?
As #webNeat said you should change the namespace that you are using in your Model.
Your Model About
<?php
namespace App\Http\Controllers;
use Illuminate\Database\Eloquent\Model;
class About extends Model
{
Controller
<?php
namespace App\Http\Controllers;
use App\About; // You have declared App\Http\Controllers in your Model
Model About Fixed
<?php
namespace App; // change to this namespace
use Illuminate\Database\Eloquent\Model;
class About extends Model
{
If you're a bit lost with Laravel or namespaces I strongly recommend you to use php artisan with each of its commands, and see and study what they do by reading all the code generated. For this case with:
php artisan make:model About
You will get a fresh new About model prepared for receive all your code with the correct namespace.
changing the namespace of your model to App should fix the issue.
<?php
namespace App; // <- here
use Illuminate\Database\Eloquent\Model;
class About extends Model
{