Laravel custom artisan command cannot access model - laravel

I'm trying to create a artisan command to dump data from database table in my existing Laravel 6 project.
I'm following the web to create the command, it works and prints out.
https://codeinphp.github.io/post/creating-your-own-artisan-in-php/
However I could not access the model in the existing project.
I've tried using
MyModel::all()
but it returns error about connection
PHP Fatal error: Uncaught Error: Call to a member function
connection() on null
I also tried do the data dump using existing getCsv() from controller, like
app('App\Http\Controllers\MyController')->getCsv();
Then it complains
Class request does not exist
I also tired doing
$table = DB::table('my_table');
But error returns as
A facade root has not been set

Related

Laravel Model reference inside Controller gives error while hosted on Heroku

I have build a Lingo game in Laravel. The app is hosted on Heroku: https://lingo-hu.herokuapp.com.
Whenever I click the 'Start Game'-button it should send a HTTP-POST-REQUEST to my WordController. After doing so it gives the following response:
"message": "Attempt to read property \"word\" on null",
"exception": "ErrorException",
"file": "/app/app/Http/Controllers/WordController.php",
"line": 23,
My WordController reference to the 'word'-model:
namespace App\Http\Controllers;
use App\word;
use App\game;
use Illuminate\Contracts\Routing\ResponseFactory;
use Illuminate\Http\Request;
class WordController extends Controller
{
}
However this action does work on my computer when running Laravel locally, just not on Heroku which I don't understand.
Console error:
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
app.js:699 Uncaught (in promise) Error: Request failed with status code 500
at createError (app.js:699)
at settle (app.js:960)
at XMLHttpRequest.handleLoad (app.js:168)
The database is up and running, I used php artisan migrate and that's working.
Anyone a suggestion on what I could be doing wrong?
The error was caused because the database table where the Word model was referring to was empty. So I imported an export from my MySQL database. Now it works!

Laravel forgot password function doesn't work

I have the default config for this since I'm new to Laravel. When I type the mail in /password/reset view it keeps loading till a timeout error is thrown in /password/email view.

PHP Warning throws ErrorException

A unit test is failing because an ErrorException about an undefined property is thrown. However, this happens in a connected shop system's core files which i cannot change.
My controller has a try ... catch block that catches the generic Exception object. But i don't want that catch to fire because of an undefined property.
I figured out the error is converted to an ErrorException in HandleExceptions.php in method handleError
How can i make phpunit ignore notices and warnings coming from code pieces i can't touch?
What i've already tried
In phpunit.xml
convertErrorsToExceptions="false"
convertNoticesToExceptions="false"
convertWarningsToExceptions="false"
Set APP_DEBUG=false as well as API_DEBUG=false for dingo.
I am using Dingo 1.0.x with Laravel 5.4 and phpunit 5.7.26.

laravel - Can I create controller from a controller?

I've a controller to create a controller. SiteController is an example.
public function createSiteController() {
$controller_name = "SiteController";
Artisan::call("make:controller",
[
"name"=>$controller_name
]);
}
It gives me following error.
file_put_contents(/Volumes/Data/www/cms/app/Http/Controllers/SiteController.php):
failed to open stream: Permission denied
Tried to set chmod("/Volumes/Data/www/cms/app/Http/Controllers", 0777), but it is not permitted.
Edit: Of course, i don't want to use 0777. It was just an example. I would never use that. I am just saying
So, I had a problem to create a controller using a controller. I was unable to do it using artisian command.
Why I need that?
I've created an artisian command. something like this. (php artisian cms:controller controllerName)
It should be extended to BaseAdminController rather than default Controller. So I've made a template to create a custom controller. Just like laravel itself does.
I've fixed this problem using below steps.
* First you need to make a new file in a temp folder.
* Manipulate/Change whatever you want in that file.
* and copy that file (Controller in my case) to your Controller folder using copy command.

Laravel Route:list not working throwing run time exception

when i tried to display all routes
by using php artisan route:list
it showing some runtime exception like this
[RuntimeException]
Session store not set on request.
how can i get my list of routes

Resources