Monday, March 28, 2016

Adding crossdomain policy security

Creating .htaccess file in your application root folder

<FilesMatch "\.(mpd||m4s|m3u8|jpg|png)$">
  <IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
  </IfModule>
</FilesMatch>


Add the XORS request middleware in laravel
<?php namespace App\Http\Middleware;
use Closure;//use Symfony\Component\HttpFoundation\Response;
class Cors {
    /**     * Handle an incoming request.     *     * @param  \Illuminate\Http\Request  $request     * @param  \Closure  $next     * @return mixed     */    public function handle($request, Closure $next)    {        header("Access-Control-Allow-Origin: *");
        // ALLOW OPTIONS METHOD        $headers = [            'Access-Control-Allow-Methods'=> 'POST, GET, OPTIONS, PUT, DELETE',            'Access-Control-Allow-Headers'=> 'Content-Type, X-Auth-Token, Origin'        ];        if($request->getMethod() == "OPTIONS") {            // The client-side application can set only headers allowed in Access-Control-Allow-Headers            return Response::make('OK', 200, $headers);        }
        $response = $next($request);        foreach($headers as $key => $value)            $response->header($key, $value);        return $response;    }
//    public function handle($request, Closure $next)//    {//        $content = $next($request);//        return ( new Response($content) )->header('Access-Control-Allow-Origin' , '*')//            ->header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT, DELETE')//            ->header('Access-Control-Allow-Headers', 'Content-Type, X-Auth-Token, Origin');//    }
}

In Kernel.php
protected $middlewareGroups = [    'web' => [        
        \App\Http\Middleware\Cors::class,
    ],

Thursday, March 24, 2016

Tuesday, March 8, 2016

Laravel server error 500

For solving the problem i ran the following commands through terminal.
sudo chmod 755 -R project_name
and then type below to allow laravel to write file to storage folder
chmod -R o+w project_name/storage
This two commands solved the problem

Wednesday, March 2, 2016

Unsupported driver [mongodb] Error

- Check whether the mongo db php driver is installed (jenssegers) for laravel
- Check whether the .dll or .so file is placed in php directory and enabled in php.ini file
- Check whether the php path is in system path
- Check whether the Mongodb driver support current PHP version
- Check the Mongodb service is registered in app.php

When problems occur like mongoclient not found error, you can try to run php from your command line and you'll see the error message there!