Laravel - Public variable in controller

Laravel - Public variable in controller

By : Camila Laranjeira
Date : November 21 2020, 11:01 PM
it should still fix some issue I want to have one public variable $users = User::all(); so i could use it in different methods inside controller and it doesn't work this way: , Try adding the assignment into the __construct() function instead:
code :

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests;
use App\User;

class AdminController extends Controller

    public $users;

    public function __construct() {
        $this->users = User::all();

    public function index()
        return view('admin.index');

    public function showUsers()
        $users = $this->users;
        return view('admin.users', compact('users'));

Share : facebook icon twitter icon
Creating a public function inside a controller in Laravel

Creating a public function inside a controller in Laravel

By : user2770896
Date : March 29 2020, 07:55 AM
I wish did fix the issue. I'm trying to create a public/private function inside my controller (say PostController) to tidy up certain code. , You need to do it like this:
code :
$startdate = $this->dateformatchange(Input::get('startdate'));
After removing public from laravel controller not working?

After removing public from laravel controller not working?

By : Janny
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , solved myself
Easy way to remove public from laravel 5 url. You just need to cut index.php and .htaccess from public directory and paste it in the root directory,thats all and replace two lines in index.php as
code :
  require __DIR__.'/bootstrap/autoload.php';
  $app = require_once __DIR__.'/bootstrap/app.php';
Use Controller with my public folder in Laravel

Use Controller with my public folder in Laravel

By : user6428271
Date : March 29 2020, 07:55 AM
seems to work fine As per our conversation in the chatroom, it appears that you modified the index.php file that resides inside the public directory. This file shouldn't be changed or modified, this is partly what powers your Laravel app.
What you need to do is create your blade views, create a controller to return the view and create a route to that controller/view and you should be okay.
How to make public accessible controller in Laravel 5.4?

How to make public accessible controller in Laravel 5.4?

By : John McGee
Date : March 29 2020, 07:55 AM
wish helps you I am not sure if my question is clear. I have a query in my controller which counts messages that are not yet been read. I inserted in one of the controller of a specific page. The result is fine when I refreshed the page but when I click to another page which means another route, it throws an error which says the variable is not declared (I notice because I inserted it only in one specific controller). The result should be notified in the header of my page view (My header is visible in all pages of my site). The problem is How can I make a single call so that the query will be applied in all pages. Bellow is the UI.enter image description here , you need to declare custom controller
code :
class BaseController extends Controller
   public function __construct() 
        $it_equipments = DB::table('it_equipments')->paginate(7);
    $areas = Areas::all(['id','area_name']);
    $dept_offs = DeptOffice::all(['id','dept_name']);
    $messages = DB::table('messages')->where('status','=', 0)->count();
    $messbody = DB::table('messages')->where('status','=', 0)->paginate(5);
Laravel: How to use controller public function for master layout

Laravel: How to use controller public function for master layout

By : user3082481
Date : March 29 2020, 07:55 AM
wish help you to fix your issue One option is to use the AppServiceProvider. In your boot method you can add:
code :
config(['livedrops' => DB::table('case_history')
              ->join('users', 'users.id', '=', 'case_history.player')
              ->join('cases', 'cases.id', '=', 'case_history.case_id')
              ->join('profiles', 'profiles.user_id', '=', 'case_history.player')
              ->join('products', 'products.id', '=', 'case_history.won_game')
              ->select('case_history.id as id', 'users.name as player', 'users.premium as vip', 'profiles.avatar as avatar', 'cases.price as price', 'products.name as game', 'products.price as gameprice', 'products.image as gameimage', 'products.color as color')
              ->orderBy('case_history.id', 'desc')
@foreach(config('livedrops') as $item)
Related Posts Related Posts :
  • Laravel: Which npm packages should be in "dependencies" vs "devDependencies"?
  • Laravel s3 check if directory exists.
  • Laravel queue job does not work in background
  • Issue in laravel 5.3 relationship?
  • Get Stripe Customer Details in Laravel 5.3 with Cashier 7.0
  • Print File Info in Laravel
  • CanResetPassword in User Model for Laravel 5.3
  • How to allow empty value for Laravel numeric validation
  • How to find and replace {{ }} tags to {!! !!} tags after upgrading a Laravel 4.2 application to 5.0
  • Laravel update column for all users based on old value
  • laravel take posts not registered by this user
  • How to insert in Laravel?
  • Gulp Invalid or unexpected token error on dateformat.js
  • How to add date with foreign key from Create function Laravel?
  • Laravel 5.2 Looping How to prevent duplicate result?
  • Getting html content api with laravel
  • Avoiding Constructor Dependency Injection in trait
  • save multiple inputs in middle table with same name Laravel
  • Laravel 5.2 How to populate edit form with multiple select?
  • Laravel cache remember forever
  • How to save data in related table in Laravel using lazy relations?
  • how broker() function in trait SendsPasswordResetEmails return \Illuminate\Contracts\Auth\PasswordBroker?
  • Is the following query is correct one?
  • Binding Vue.js to all instances of an element, without(?) using Components
  • Configure Crontab to execute Laravel Task Scheduling
  • How to append 3 parameters in select box in blade in Laravel 5.2?
  • Laravel 5.2 - Installing intervation image error command
  • Fetching post comment order by in laravel
  • How can I filter a query using laravel relationships
  • Laravel 5.2 testing How to follow DRY principle?
  • Laravel 5.3 Query Relationship data in view
  • wherePivot group priorities (and/or)
  • PHP Artisan Tinker not working with Laravel 5.5.16
  • Foreach ul li as an infinity condition
  • How to open file from storage by URL address?
  • How can I solve Call to undefined method Illuminate\Notifications\Messages\MailMessage::bcc() on laravel notification?
  • Merging two queries into one using Eloquent
  • shadow
    Privacy Policy - Terms - Contact Us © soohba.com