Clearly, I'm missing something obvious here.
I have replaced part of the base path with "base-path-hidden", but I verified the real path was correct multiple times by copying and pasting it from the error messages and using the cd command to get to that specific directory to ensure it wasn't something stupid like a typo.
In the web.php file I started with:
Route::get('/my-test', function () {
$path = base_path('vendor') . '/testvendor/testproject/providers';
return 'Hello Test!' . $path;
});
Returns the full "Hello Test" in the web browser along with the full path to the class dir. Again, I then pasted the path onto the CLI. Using cd I got to the class dir as expected.
##########################################
I then changed the web.php to route it to my custom plugin provider class.
This however is where I'm missing something obvious. I'm still new to Laravel and the MVC approach and I feel like I'm going in circles trying to figure this out and the docs don't cover a custom vendor route in enough detail for me to resolve this. I've tried a lot of tweaks and variations, but so far haven't gotten past this stupid class not being recognized. I just know it's going to be a full facepalm when someone points out the obvious thing I'm missing.
My intention here is to develop this as a plugin versus adding it to the root app. I realize my life would probably be easier if I just did it in the main App dir, but I need to get comfortable with creating plugins and how to do this. I think it would be easier/cleaner in the long run anyway to keep it separate. Maybe I'm just missing something obvious with that approach too. :)
web.php:
Route::get('/my-test', base_path('vendor') . '/testvendor/testproject/providers/TestServiceProvider@register::class');
After clearing the route, etc. on the CLI, this is what I get in the browser.
Target class [/base-path-vendor-hidden/vendor/testvendor/testproject/providers/TestServiceProvider] does not exist.
Again, I paste that full path (minus the class name) and get right to my test providers dir. I vi into the TestServiceProvider.php file and the contents are below.
What am I doing wrong?
use Illuminate\Support\ServiceProvider;
class TestServiceProvider extends ServiceProvider
{
/**
* Register services.
*
* @return void
*/
public function register()
{
return('TSP - TEST SUCCESS!!!!!!!!');
}
/**
* Bootstrap services.
*
* @return void
*/
public function boot()
{
//
}
}
I've also tried psr-4 and namespaces too, but couldn't make either of them work either. I get the basic concept of both of those, but clearly, I am missing something there too. I only mention it in case someone suggests that as my solution.
In fact, I would love to know how to do this both manually like I'm trying, and with namespaces and psr-4. I really need to learn all three approaches and I thought I got the basics, but clearly not.
Thank you in advance to anyone willing to help!