Laravel where in query

Laravel where in query
How would I do this with Laravel?
SELECT movie.title
FROM movie
WHERE movie.id IN
(SELECT session.movie_id FROM session WHERE session.id = :id and date = :date)

Answer:

First off you will need a database with movies and sessions tables and two models in Laravel.
Movie Model
    <?php namespace App;

    use Illuminate\Database\Eloquent\Model;

    class Movie extends Model {

      protected $fillable = ['title'];

      public function sessions()
      {
          return $this->hasMany('App\Session');
      }
      }
    ?>
Session Model
    <?php namespace App;

    use Illuminate\Database\Eloquent\Model;

    class Session extends Model {

      public function movies()
      {
          return $this->belongsTo('App\Movie','movie_id');
      }
    ?>
The query in your Controller would have a method like.
public function show($id)
{
    try {
        $movie = Movie::with('sessions')->where('id',$id)->firstOrFail();
    }
    catch(ModelNotFoundException $exception)
    {
        abort(404);
    }
    return view('movies.show')->withMovie($movie);
}

You can try:
$movie = Movie::whereIn('id', function($query) use ($id, $date) {
    $query->select(DB::raw('session.movie_id'))
          ->from('session')
          ->whereRaw('session.id = ? and session.date = ? array($id, $date));

})
->get();

Installing Laravel

Installing Laravel
I am on a windows 8 machine and I'm trying to learn laravel. I copy and pasted my PHP folder from C:\xampp to C:\php, installed composer, ran composer install then composer create-project laravel/laravel learning-laravel. So far everything was created so I went into the directory and tried to use 'php artisan serve' and got the following error.
C:\Users\denni_000\learning-laravel>php artisan serve
Warning: require(C:\Users\denni_000\learning-laravel\bootstrap/../vendor/autoloa
d.php): failed to open stream: No such file or directory in C:\Users\denni_000\l
earning-laravel\bootstrap\autoload.php on line 17

Answer:


try to follow the installation guide from Laravel
1-get Composer: Composer.
Like Laravel.com says: "Make sure to place the ~/.composer/vendor/bin directory in your PATH so the laravel executable can be located by your system."
On CMD type the follow
2-
Composer global require "laravel/installer=~1.1"
3-
laravel new blog
"laravel new" command will create a fresh Laravel project on the directory you specify. You also can create a project with composer, like that :
composer create-project laravel/laravel --prefer-dist

Laravel optimization

Laravel optimization
So I've heard, because Laravel is easy to develop, it loads a whole bunch of dependancies which may or may not be needed. I want to optimize Laravel for the sake of better performance, and I wonder if there's any plugins I could utilize so as to find out and remove unwanted Laravel classes/services to suit exactly my own needs?

Answer:

use these commands in terminal-
composer dump-autoload -o
php artisan optimize
-o flag create the optimized autoload file.

if you are on debuging mode :: on you laravel project directory
run
php artisan optimize --force
else
run
php artisan optimize on you project folder
(It will optimize Laravel Framework for Better Performance as much as possible)

Laravel IoC outside Laravel

Laravel IoC outside Laravel
I am using this repo as the basis for a new CLI PHP project using Eloquent as the ORM.
When you create the new Eloquent capsule you have the option to setAsGlobal which makes the DB capsule accessible from anywhere in the code.
Does that mean there's a Laravel Container being used? Or is this just affecting the DB object?
I'd been using pimple as a container, but if Laravel already has a container I can bind to via Eloquent, that would be a lot simpler-- I want to bind a log writer, the Eloquent capsule, and probably a settings object to the global container so I can access it from anywhere.
Answer:
No it does not use Laravels Container. If you look at the method in the trait: (github.com)
public function setAsGlobal()
{
    static::$instance = $this;
}
You can see that it just sets a static property on the class containing the current instance so it will be reused for subsequent calls.

Laravel jrenton/laravel-scaffold

Laravel jrenton/laravel-scaffold
I am starting to use laravel and i am having problems with jrenton/laravel-scaffold library. When i use its scaffold it generates everything, but the controllers are empty files. I`m generating from a file shown in the github page of the library:
resource = true
namespace = Oxford
University hasMany Department string( name city state homepage ) -nt
Department belongsTo University, hasMany Course string( name description ) number:integer
resource = false
Course belongsTo Department, hasMany Lesson string( name description ) integer( number credits ) -sd
If you need more information ask in the comment section.
Answer:
There's a template folder that contains Controller and View templates to use with the scaffolding. Check under the 'resource' and 'restful' folders for them at: https://github.com/jrenton/laravel-scaffold/tree/master/src/Jrenton/LaravelScaffold/templates

Error in exception handler. - Laravel

Error in exception handler. - Laravel
It's a Laravel-install related question. I have a public-facing Unix server setup:
<VirtualHost *:80>
ServerAdmin webmaster@mydomain.org
DocumentRoot "/var/www/mydomain"
ServerName mydomain.org
ServerAlias www.mydomain.org
ErrorLog "/var/log/mydomain.org-error_log"
CustomLog "/var/log/mydomain.org-access_log" common
</VirtualHost>
I can serve documents fine out of /var/www/mydomain i.e. http://mydomain.org/test.php with test.php containing:
<?php echo 'test';
works fine.
In bash, with Laravel installed through Composer and looking at the files:
# ls /var/www/mydomain/my-laravel-project

.gitattributes  CONTRIBUTING.md artisan         composer.json   phpunit.xml readme.md       vendor
.gitignore      app             bootstrap       composer.lock   public          server.php
So when I browse to:
http://mydomain.org/my-laravel-project/public/
why does my application report:
Error in exception handler. 
in the browser - on a blank white screen? I'm expecting to see the Laravel splash screen.
Moreover, the log files don't reveal anything either.
Answer:

The safer option would be to change the group of the storage directories to your web servers group (usually apache or www-data, but this can vary between the different operating systems) and keep the permissions as of the directory as 775.
chgrp -R www-data app/storage
Or with chown.
chown -R :www-data app/storage
Then make sure directory permissions are 775.
chmod -R 775 app/storage
From the Laravel web site:
Laravel may require one set of permissions to be configured: folders within app/storage require write access by the web server.

run laravel downloaded project on local machine

run laravel downloaded project on local machine
I am trying to install an Laravel Framework project run on my local machine.
error
Please help me.

Answer:
From PHP.net:
Windows users must include the bundled php_fileinfo.dll DLL file in php.ini to enable this extension.
Check your php.ini file to ensure the .dll file is listed. The line is probably there and looks like ;extension=php_fileinfo.dll so just remove the ;.