Closed xLuisCumbi closed 4 years ago
Hi. I need more information about the problem. When did you get this error?
There was a problem in older version and it was fixed https://github.com/butschster/LaravelMetaTags/commit/b1228fef55227dc519fe8efb25cdef21358ac9bc
The problem caused only when console commands were run. Maybe do you have this code
public function register()
{
// This condition will be removed
if (!$this->app->runningInConsole() || $this->app->runningUnitTests()) {
$this->registerPackageManager();
$this->registerMeta();
$this->packages();
}
}
in the service provider App\Providers\MetaTagsServiceProvider
.
The register
method should look like over there https://github.com/butschster/LaravelMetaTags/blob/master/src/Providers/MetaTagsApplicationServiceProvider.php#L25
There is no Register method in App\Providers\MetaTagsServiceProvider. This is the code in that class:
protected function packages()
{
// Create your own packages here
}
// if you don't want to change anything in this method just remove it
protected function registerMeta(): void
{
$this->app->singleton(MetaInterface::class, function () {
$meta = new Meta(
$this->app[ManagerInterface::class],
$this->app['config']
);
// It just an imagination, you can automatically
// add favicon if it exists
// if (file_exists(public_path('favicon.ico'))) {
// $meta->setFavicon('/favicon.ico');
// }
// This method gets default values from config and creates tags, includes default packages, e.t.c
// If you don't want to use default values just remove it.
$meta->initialize();
return $meta;
});
}
And what about version? When did you get this error?
I'll try to explain what's happening.
I followed the install instructions
And i created this class:
use Butschster\Head\MetaTags\MetaInterface;
use App\Repositories\BlogsRepository;
class BlogsController extends AppBaseController
{
/** @var BlogsRepository */
private $blogsRepository;
protected $meta;
public function __construct(BlogsRepository $blogsRepo, MetaInterface $meta)
{
$this->meta = $meta;
$this->blogsRepository = $blogsRepo;
}
public function blogPosts()
{
$blogPosts = Blogs::where('status', '=', 'Active')->paginate(4);
$data['blogPosts'] = $blogPosts;
$this->meta
// Will render "Home page - Default Title"
->prependTitle('Home page')
// Will include next, prev, canonical links
->setPaginationLinks($data)
// Will change default favicon
->setFavicon('/favicon-index.ico');
return view('front.blog.blogPosts')->with($data);
}
Now I'm getting this error:
Class Butschster\Head\MetaTags\MetaInterface does not exist
What I'm doing wrong? I really wants to use this library, but please help me. Let me know if you need more information. Thanks in advance
Will be awesome if you have a full example/tutorial.
There can be two reasons.
App\Providers\MetaTagsServiceProvider
, but you don't have any.config/app.php
@Luismij If your are in same situation, remove app/Providers/MetaTagsServiceProvider.php
, App\Providers\MetaTagsServiceProvider::class,
line from config/app.php
and config/meta_tags.php and run composer remove butschster/meta-tags
. Install again. After installation run php artisan optimize:clear
. This procedure works for me.
@majorsabbir Thank you!!! I had the same issue after installing on Laravel 7. I followed your instructions and it fixed the error.
Thank you I'll try it and let you know if works for me
@majorsabbir I still have this problem also tried uninstalling and all (found out App\Providers\MetaTagsServiceProvider::class) wasent added to my cofig/app.php
@livevsonline make sure you uninstall LaravelMetaTags first. run php artisan config:clear
, then follow the installation process again Laravel Meta Tags Installation. if it still doesn't work run php artisan optimize
.
Note: After running php artisan meta-tags:install
command if you found there is no meta-tags.php in config folder, check your current user permission.
I'm getting this error in LAravel 6 Target [Butschster\Head\Contracts\MetaTags\MetaInterface] is not instantiable.
Please help