spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
  Home » LARAVEL » Page 1
Laravel query where value equals value in another table
$items = DB::table('negotiations') ->join('negotiations_statuses', 'negotiations.id', '=','negotiations_statuses.negotiation_id') ->whereNotExists(function($query){ $query->where('status_id', '<>', 3) ->where('status_id', '<>', 4); }) ->get(); This query will get all items that are not completed or rejecte

Categories : Laravel

Laravel remember me functionality with Sentry
Rather than storing a value in the remember_token field, Sentry's authenticate method sets a cookie if the remember flag is true. Technically, the login() method is called by authenticate() and sets the cookie. Here's the relevant code: public function login(UserInterface $user, $remember = false) { ... (snip) if ($remember) { $this->cookie->forever($toPersist); }

Categories : Laravel

Facing an issue with routing - Laravel
Try putting the Route::resource as the last route. Laravel will try all routes in the order you put them in the route file, so when you put the resource route first only this one will be checked because it expects all admin routes to be there. Route::group(array('before' => 'auth'), function() { Route::get('admin/test', array('uses' => 'VacatureController@create')); Route::post('adm

Categories : Laravel

1 Laravel app, 2 domain names & different route groups
You can create a route group for each subdomain and then use a 'before' filter on each group. Route::filter('domain1', function($request) { $uri = Request::path(); //this might be in $request $matches = preg_match('^https?://([a-zA-Z)]+)./', $uri); $subdomain = $matches[1]; Session::put('domain', $subdomain); //you can use Session::get('domain'); to retrieve this //for your o

Categories : Laravel

Laravel, custom functions in for views
I would pop some client side code into your views and access a route to a controller action (which returns JSON by default) and conditionally add that particular snippet into your view (via a variable passed to the view that determines if the person is logged in). Then you can apply an auth filter to your route to protect it. Note: with this approach you can pass url parameters to your action. Th

Categories : Laravel

Laravel 4/5, order by a foreign column
I would recommend using join. (Models should be named in the singular form; User; Detail) $users = User::join('details', 'users.id', '=', 'details.user_id') //'details' and 'users' is the table name; not the model name ->orderBy('details.name', 'asc') ->get(); If you use this query many times, you could save it in a scope in the Model. class User extends Eloquent { public f

Categories : Laravel

Querying Relations Laravel Eloquent ORM
I'm pretty sure what you actually need is a many-to-many relationship found here public function items(){ return $this->belongsToMany('Items', 'items_sold'); } Is you model really called "Items"? If it's actually "Item", change to first parameter in the above code accordingly

Categories : Laravel

Sentry add User to Group
So I found out why, my model class for the config file was named Users, so I'm guessing that's where it get the 'users_id' when trying to save to that column. Previous: 'model' => 'UAQModelsAccountUsers', Fixed it: 'model' => 'UAQModelsAccountUser',

Categories : Laravel

Confide login view
You could store the message in a session variable and then display it on the login screen. Session::flash is especially suited for such a situation. It makes the variable available for the next request and then deletes it. Session::flash('message', 'Please login to see this content'); And then in the login view @if(Session::has('message') <p>{{ Session::get('message') }}</p> @

Categories : Laravel

Composer fails, package needs another package in require-dev
Take a look here and try some of the different versions: https://packagist.org/packages/vespakoen/menu Ex: "vespakoen/menu": "2.0.15"

Categories : Laravel

Laravel and AWS Elastic Beanstalk - File Permissions
The issue was that I had ignored the logs directory so it wasn't on the server at all. It's not that the server couldn't write to it, it's that it didn't exist. The default permissions for an instance created by Elastic Beanstalk are: File 664 Dir 775 They are deployed and owned by the Apache user.

Categories : Laravel

Checking First Character of a String with Blade Template
This logic really belongs somewhere other than the view/template layer. A View Composer could be a better location, or perhaps even a model method to return your data separated by starting letter - thus returning a hash of arrays containing artists under each letter. Example code: class Artist extends Eloquent { public static function allByFirstCharacter() { $artists = Artist::orderBy('

Categories : Laravel

Best way to handle multi-table Laravel migrations that failed halfway through?
the best way to do it is to back up your db entries. There could be multiple fatal errors during your migration. When you changes the column in a specific table, make sure you add everything first and then delete or remove the columns you do not want. Because removal is a rather dangerous move, you need to make sure it is done after other possible operations are done. To further decrease the risk

Categories : Laravel

How to properly filter your route::group in Laravel 4?
The problem is this: If you don't have a prefix defined for your groups, Laravel makes no difference between a route in one group and a route in the other (that share the same url) Because what Laravel does first, is searching for the matching route. All the filter stuff is done afterwards (even if its a before filter). In your case that means that, for example Route::get('distributors/{id}', ar

Categories : Laravel

Laravel loading two models into one list
DB::table('users') ->leftJoin('comments', 'users.id', '=', 'comments.user_id') ->leftJoin('articles', 'users.id', '=', 'articles.user_id') ->paginatuse(30);

Categories : Laravel

What's the cleanest way to remove Homestead and Vagrant from a Windows system?
Virtual Machine Remove the homestead VM by running vagrant box remove laravel/homestead Homestead If you installed Homestead via composer with the following command: composer global require laravel/homestead run the opposite to remove it: composer remove laravel/homestead This will remove the .composer/vendor/laravel directory, including its 'homestead' subdirectory. The 'global' keyw

Categories : Laravel

Laravel can't detect environment variables set by Forge when run from console
When you're running from the command line, no environment is set as those are for the HTTPD. Console requests do not go through nginx, just PHP. You can set the environment for the command you're running, with the --env option. Example: php artisan migrate --env=develop

Categories : Laravel

Creating entry with eloquent - unexpected behavoiur
Let's try this // app/models/Location.php class Location extends Eloquent { } // app/models/Department.php class Department extends Eloquent { } and the migration to update Schema::create('contacts', function(Blueprint $table) { $table->increments('id'); $table->string('firstname'); $table->string('lastname'); $table->integer('location_id')->unsigned(); $tab

Categories : Laravel

Call to undefined method IlluminateDatabaseEloquentCollection::with()
The function all() executes the query so you get a collection. You have to call with on a query builder instance. Meaning you should do this: foo::with('foos', 'bars')->get(); Also, classes start with a capital letter by convention so it should be Foo ;)

Categories : Laravel

Laravel log not showing system time
Look at your app/config/app.php There should be a field called timezone in which you could specify app-wide timezone, including your logs to match your system timezone.

Categories : Laravel

How to get the month duration in Laravel
Basically, it is Carbon $start = new Carbon(date('Y-m-d', strtotime(Input::get('startdate')))); $end = new Carbon(date('Y-m-d', strtotime(Input::get('enddate')))); $diff_days = $start->diff($end)->days; Well, there are more, please look up the documentation for details: https://github.com/briannesbitt/Carbon#api-difference

Categories : Laravel

How to Force a Unique Rule To Ignore A Specific User in Laravel 4?
There's probably many ways to do this but one that comes to my mind is this. Just don't validate the username or email if the user hasn't changed it. $user = User::where('code','=', Input::get('code'))->firstOrFail(); $validationRules = array( 'password' =>'required|min:6', 'password_again' =>'required|same:password', 'logo_path' =>'max:255' ); if($use

Categories : Laravel

How to access public folder in laravel 4?
Your directory structure is different from the default one shown here You have to put the packages folder and these files into the public directory: .htaccess favicon.ico index.php robots.txt Then to make your site work again change the document root of your apache server to path/to/application/public There's a reason for the public directory. When you put it on a server on the internet you

Categories : Laravel

Parent, Child, Child of Child in Laravel
This is because cities is a Collection you have to loop through each of them to get the jobs number and add them up. Within controller: Like so; $job_count = 0; $province->cities->each(function ($city) use ($job_count){ $job_count += $city->jobs->count(); }); The $job_count would be equal to the total number of jobs within each of it cities. Please Note: Be sure to eager lo

Categories : Laravel

Publishing site created with Laravel error
I don't know about that hosting but for other hosting service such as JustHost, GoDaddy, BlueHost, HostGator... I deploy the Laravel web pretty much easy. 1) Access to the host via SSH, get the source code $ cd www/ $ git clone https://github.com/ME/MY-PROJECT.git . 2) Get Composer: $ curl -sS https://getcomposer.org/installer | php -- --filename=composer 3) Update all dependencies (/v

Categories : Laravel

how to implement the code below in laravel for a password
Place this in your routes.php Route::get('hash/{password}', function($password){ echo Hash::make($password); }); And then open your-project.dev/hash/JohnDoe in your browser.

Categories : Laravel

Queries with queues on Laravel
A queue is a server side processing event, that is meant to occur after the user does something. For example, after the user signs up, the system 'queues' an email, so it can return to the user quickly, and send the email later. You cannot use Laravel 'queues' for page loading. This is a user-side event that needs to happen immediately. Your use of ajax to load slow elements after the initial pa

Categories : Laravel

Laravel subdomain config
You can update the detectEnvironment method to use a closure function and run your login in there to determine if your application is local or not. update bootstrap/start.php like this: $env = $app->detectEnvironment(function() { return preg_match('/staging/', $_SERVER['HTTP_HOST']) ? 'staging' : 'production'; }); Now when you are visiting your laravel project from http://staging.xxx UR

Categories : Laravel

About Laravel - How to use function string in view
Is {{ $show->content }} returning any data to format? Is your template is .blade? Maybe it placed somewhere in HTML, where it is not visible? Try to use this construction with some predefined string to find out if it works. Here is working example: {{ str_limit('Some big text', $limit = 5, $end='...') }}

Categories : Laravel

vagrant / homestead up - connection timeout ONLY on home network
Don't forget to add the "domains" for your Nginx sites to the hosts file on your machine! The hosts file will redirect your requests for the local domains into your Homestead environment. On Mac and Linux, this file is located at /etc/hosts. On Windows, it is located at C:WindowsSystem32driversetchosts. The lines you add to this file will look like the following: 192.168.10.10 homestead.app In

Categories : Laravel

Group collection by date in Laravel
This may be a very basic approach but that's how I always do it: <?php $currentDate = null ?> @foreach($agendas as $agenda) <?php $date = date("d M Y",strtotime($agenda->start_time)); ?> @if($currentDate != $date) <?php $currentDate = $date; ?> <h3>{{ $date }}</h3> @endif {{-- do the stuff --}} @endforeach It would be nice (and b

Categories : Laravel

Loading multiple select options into array
Use name attribute as name="PaymentStatus[]" to return an array, so you can get selected options with: $paymentstatus = Input::get('PaymentStatus');

Categories : Laravel

Laravel: Base table or view not found: 1146 La Table 'database.migrations'
You can try this: In your phpMyAdmin: create the database. In your command console: 1) In your proyect folder execute: php artisan migrate:install This will create the table "migrations" in your database 2) Then execute: php artisan migrate

Categories : Laravel

Error refreshing the OAuth2 token, message: '{ "error" : "invalid_grant" }'
I didn't use this package before, I'm using google-api-php-client, but anyways, this error occurs if you don't set the refresh token. You should know that you need to have the access token ONLY once. You also need to set the access type to be offline, which will provide you with a refresh token that you will use to automatically get a new access token without getting a new code every time your a

Categories : Laravel

Extending the Laravel EloquentCollection Class
You will need to replace the pagination service provider, amongst a couple of other classes in the pagination library. By the sound of it you know how to do it this way, but were hoping for another answer, but as I have the code I'll drop it in here for you. The reason you need to replace these classes/methods is because the files in Illuminate directly reference instances of classes within the I

Categories : Laravel

Is it safe to commit compiled.php file for Laravel?
It depends on your deployment process and of what you include in the compiled.php file. If you add composer.lock in your version manager, only run composer install when you deploy and add nothing in config/compile.php, yes it is quite safe. But what is the gain ? You just have to put this in composer.json: "scripts": { "post-install-cmd": [ "php artisan clear-compiled", "php

Categories : Laravel

Laravel eloquent count hasMany relations
Laravel when actually assume the table name if one is provided, and it does so by making plural of the model name. To your model, add: class Establissment extends Eloquent { protected $table = 'thetablenamehere'; } Also, naming a table as plural is considered best practise.

Categories : Laravel

Laravel Route [front.profiles.store] not defined
Try to run the below command at your project's path. composer dump-autoload You may need to add the namespace to composer.json, under the autoload object: "autoload": { "psr-0": { "Front": "app/controllers/front" } After that, execute again the command.

Categories : Laravel


Recently Add
Defining has one relationship with Laravel
Laravel query where value equals value in another table
Laravel remember me functionality with Sentry
Facing an issue with routing - Laravel
1 Laravel app, 2 domain names & different route groups
Laravel, custom functions in for views
Laravel 4/5, order by a foreign column
Querying Relations Laravel Eloquent ORM
Sentry add User to Group
Confide login view
Composer fails, package needs another package in require-dev
Laravel and AWS Elastic Beanstalk - File Permissions
Checking First Character of a String with Blade Template
Best way to handle multi-table Laravel migrations that failed halfway through?
How to properly filter your route::group in Laravel 4?
Laravel loading two models into one list
What's the cleanest way to remove Homestead and Vagrant from a Windows system?
Laravel can't detect environment variables set by Forge when run from console
Creating entry with eloquent - unexpected behavoiur
Call to undefined method IlluminateDatabaseEloquentCollection::with()
Laravel log not showing system time
How to get the month duration in Laravel
How to Force a Unique Rule To Ignore A Specific User in Laravel 4?
How to access public folder in laravel 4?
Parent, Child, Child of Child in Laravel
Publishing site created with Laravel error
how to implement the code below in laravel for a password
Queries with queues on Laravel
Laravel subdomain config
About Laravel - How to use function string in view
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.