Search code examples
phplaravellaravel-backpack

Laravel 6.x Backpack NewsCrud Plugin


What I want to do is allow the admin panel to post news using newscrud. I am confused in how would I grab the information from the database and show the user the articles.

I am having trouble using the newscrud plugin for laravel. I quite don't understand how to use this plugin. I have installed it using composer. All the controllers, models etc. are in the vendor folder in my Laravel project.

Attempts: What I tried to do is make a function in the laravel-project/vendor/backpack/newscrud/src/app/Http/Controllers/Admin/ArticleCrudController.php file:

public function index()
{
    # Pass the article database information in articles var
    $articles = Articles::all();

    # Return this variable to blog page
    return view ('blog')->with('articles', $articles);
}

And in the routes/web.php file:

Route::get('/blog', 'ArticleCrudController@index')->name('blog');

Front-end code

                      @foreach($articles as $article)

                          <div class="col-md-12 d-flex ftco-animate">

                            <div class="blog-entry align-self-stretch d-md-flex">

                              <a href="blog-single.html" class="block-20" style="background-image: url('images/image_6.jpg');">

                              </a>

                              <div class="text d-block pl-md-4">

                                <div class="meta mb-3">

                                  <div><a href="#">July 20, 2019</a></div>

                                  <div><a href="#">Admin</a></div>

                                  <div><a href="#" class="meta-chat"><span class="icon-chat"></span> 3</a></div>

                                </div>

                                <h3 class="heading"><a href="#">Even the all-powerful Pointing has no control about the blind texts</a></h3>

                                <p>Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts.</p>

                                <p><a href="blog-single.html" class="btn btn-primary py-2 px-3">Read more</a></p>

                              </div>

                            </div>

                          </div>

                    @endforeach    

Error The error message I get is:

Target class [App\Http\Controllers\ArticleCrudController] does not exist. 

If you need information/screenshots I am willing to provide them.


Solution

  • When using composer in PHP, you should never make modifications to files inside the /vendor/ folder. Because as soon as you run composer update, they will get overwritten.

    If I understand correctly, What you’re trying to do has little to do with Backpack. You should not overwrite the package in the vendor folder. You should create a controller in your app folder, with a routes in your routes folder, line you would normally do in Laravel. Just make sure that, when you reference the model, you reference Backpack\NewsCRUD\app\Models\Article instead of App\Models\Article.

    Hope it helps!