Showing posts with label Database. Show all posts
Showing posts with label Database. Show all posts

Tuesday, March 7, 2017

[ANSWERED]Deploying laravel php app with pgsql on heroku

I am trying to deploy laravel php app on heroku,the app deployed perfectly without DB but when i try to add the postgresql addon in my application it doesnt show any error in the cmd and also i have a login and register page, both are also working prefectly,I am able to register and login without any problem.
But he problem is when i try to open any other pages that is connected to dB. it shows the error on my browser
"Whoops, looks like something went wrong."
I am not getting any other errors.i dont know what is happening. If somebody can help.thanks
The steps i adopted to deply are.
$ git init
$ git add .
$ git commit -m "new laravel project"


$echo web: vendor/bin/heroku-php-apache2 public/ > Procfile
$ git add .
$ git commit -m "Procfile for Heroku"

$heroku create

$ heroku config:set APP_KEY= key
$git push heroku master

now for the pgsql i did..
 $ heroku addons:add heroku-postgresql:hobby-dev

$ heroku config

Changed the value of 'default' in app/config/database.php to 'pgsql'.
'default' => 'pgsql',

At the top of database.php:
$url = parse_url(getenv("DATABASE_URL"));

$host = $url["host"];
$username = $url["user"];
$password = $url["pass"];
$database = substr($url["path"], 1);

Then change your pgsql entry in that same file to be the following:
'pgsql' => array(
    'driver'   => 'pgsql',
    'host'     => $host,
    'database' => $database,
    'username' => $username,
    'password' => $password,
    'charset'  => 'utf8',
    'prefix'   => '',
    'schema'   => 'public',
),


$ git add .
$ git commit -m "Convert to use Heroku PostgreSQL database"
$ git push heroku master
$ heroku run php artisan migrate



via Hassan Haroon

Friday, March 3, 2017

[SOLVED]Laravel: PDOException: could not find driver

I am developing a website on a server I only have access to MySQL and FTP, so all commands I run are through the b374k php shell . I am experiencing a Laravel problem with SQL driver. I tried switching to file-hosted SQLite (in database/database.sqlite), but the thrown exception is the same as when using MySQL. The input & output of the console is as follows:
   php artisan migrate:refresh --seed
    [Illuminate\Database\QueryException]
could not find driver (SQL: select * from sqlite_master where type = 'table ' and name = migrations)
 [Doctrine\DBAL\Driver\PDOException]
could not find driver
 [PDOException]
could not find driver

The Apache extensions installed on the server are:
    /etc/php/5.6/apache2/conf.d/10-mysqlnd.ini, 
/etc/php/5.6/apache2/conf.d/10-opcache.ini,
 /etc/php/5.6/apache2/conf.d/10-pdo.ini,
 /etc/php/5.6/apache2/conf.d/15-xml.ini, 
/etc/php/5.6/apache2/conf.d/20-calendar.ini,
 /etc/php/5.6/apache2/conf.d/20-ctype.ini, 
/etc/php/5.6/apache2/conf.d/20-curl.ini,
 /etc/php/5.6/apache2/conf.d/20-dom.ini, 
/etc/php/5.6/apache2/conf.d/20-exif.ini, 
/etc/php/5.6/apache2/conf.d/20-fileinfo.ini, 
/etc/php/5.6/apache2/conf.d/20-ftp.ini, /etc/php/5.6/apache2/conf.d/20-gd.ini, 
/etc/php/5.6/apache2/conf.d/20-gettext.ini, 
/etc/php/5.6/apache2/conf.d/20-iconv.ini, 
/etc/php/5.6/apache2/conf.d/20-json.ini, 
/etc/php/5.6/apache2/conf.d/20-mbstring.ini, 
/etc/php/5.6/apache2/conf.d/20-mcrypt.ini, 
/etc/php/5.6/apache2/conf.d/20-mysql.ini, 
/etc/php/5.6/apache2/conf.d/20-mysqli.ini, 
/etc/php/5.6/apache2/conf.d/20-pdo_mysql.ini,
 /etc/php/5.6/apache2/conf.d/20-phar.ini, 
/etc/php/5.6/apache2/conf.d/20-posix.ini, 
/etc/php/5.6/apache2/conf.d/20-readline.ini, 
/etc/php/5.6/apache2/conf.d/20-shmop.ini, 
/etc/php/5.6/apache2/conf.d/20-simplexml.ini, 
/etc/php/5.6/apache2/conf.d/20-sockets.ini,
 /etc/php/5.6/apache2/conf.d/20-sysvmsg.ini,
 /etc/php/5.6/apache2/conf.d/20-sysvsem.ini,
 /etc/php/5.6/apache2/conf.d/20-sysvshm.ini,
 /etc/php/5.6/apache2/conf.d/20-tokenizer.ini, 
/etc/php/5.6/apache2/conf.d/20-wddx.ini,
 /etc/php/5.6/apache2/conf.d/20-xmlreader.ini, 
/etc/php/5.6/apache2/conf.d/20-xmlwriter.ini, 
/etc/php/5.6/apache2/conf.d/20-xsl.ini, 
/etc/php/5.6/apache2/conf.d/20-zip.ini

What can be the problem and how can I fix it? (I don't have access to root bash)


via artus90

Monday, February 27, 2017

[SOLVED]how to add multiple scope to DB::table in laravel 5.4

I am new on laravel 5, I was trying to add multiples scopes like this:
$projects = DB::table('projects AS p')->select('p.project_name','c.name_country', 'p.date_project','s.name_status','p.rejected_date')                    
                    ->join('country AS c','c.id','=','p.id_country')
                    ->join('status AS s','s.id','=','p.id_status')
                    ->where('p.active','=','1');  

$projects = $this->scopeCountry($projects , $country);
$projects = $this->scopeStatus($projects , $status);  
$projects->get(); 
return view('search.ajax')->with('projects', $projects);
}
    public function scopeCountry($query, $country){
            return is_null($country) ? $query : $query->where('p.id_country','=',$country);
        }

public function scopeStatus($query, $status){
            return is_null($status) ? $query : $query->where('p.id_status','=',$status);
        }
}

It gave me this error: ErrorException in 26864233b0cd26a1055b66c2645628be451523fd.php line 4: Undefined property: Illuminate\Database\MySqlConnection::$project_name (View:/home/vagrant/Code/projects/resources/views/search/ajax.blade.php)
I noticed that this error doesn't show up if I modify it like this:
//$projects = $this->scopeStatus($status);  
//$projects->get(); 

And then I add the get() function in:
public function scopeCountry($query, $country){
                return is_null($country) ? $query->get() : $query->where('p.id_country','=',$country)->get();
            }

The reason why I don't add the queries in one scope and I use is_null($country), is because in case those variables($country, $status) were null only the main query should be executed:
$projects = DB::table('projects AS p')->select('p.project_name','c.name_country', 'p.date_project','s.name_status','p.rejected_date')                    
                        ->join('country AS c','c.id','=','p.id_country')
                        ->join('status AS s','s.id','=','p.id_status')
                        ->where('p.active','=','1'); 

And also I have to add similar scopes to another fields, maybe there is another way to do it, I am not sure. Thank you.



via Luis

[SOLVED] Update auto Create_at & Update_at columns at laravel 5.4

here some simple code i have. actuly i was trying to insert some Tag to my database and no problem to that.but once insert my tag "created_at" & "updated_at" columns not update and just NULL how can i update auto this fields? i don't have any model just migration here my tag migration:
public function up()
{
    Schema::create('tags', function (Blueprint $table) {
        $table->increments('id');
        $table->string('tag');
        $table->timestamps(); 
    });




via siros

[SOLVED]Add new column to database table with migrations fails with - Nothing to migrate

I just learned how to use Migrations. I successfully created a table with this schema:
/**
 * Run the migrations.
 *
 * @return void
 */
public function up()
{
    Schema::create('units', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->string('description');
        $table->timestamps();
    });
}

Unfortunattely I missed the column path, so I've tried to add it. First I informed myselfe in the laravel documentation to learn how to add new columns.
From the documentation:
The table method on the Schema facade may be used to update existing tables.
My attempt:
/**
 * Run the migrations.
 *
 * @return void
 */
public function up()
{
    Schema::create('units', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->string('description');
        $table->timestamps();
    });

    Schema::table('units', function (Blueprint $table) {
        $table->string('path');
    });
}

However, after executing php artisan migrate I get Nothing to migrate.
What am I doing wrong?


from Latest question asked on Laravel tag.

via EdwardBlack

[SOLVED]Query retrieve bad record

somthing wrong, when I run a query to retrieve a record in my database with a wrong ID I receive the result of another recording! Example :
The ID entered is =91TDFS78.
The result retrieve is of ID = 91.
in below query:
$idusers = \DB::table('users')
            ->select('users.*')
            ->where('id','=', $id)
            ->get();



from Latest question asked on Laravel tag.

via nabil UPDATE: Thank you for all, I have to do the test before running the query :
$isdigit = ctype_digit((string)$id);
if($isdigit){
$idusers = \DB::table('users')
            ->select('users.*')
            ->where('id','=', $id)
            ->get();
}

[SOLVED]Run a raw SQL statement to rename an index in a Laravel migration

I want to run the following raw SQL statement in a Laravel migration:
RENAME INDEX offer_venue_id_fk_idx TO offers_venue_id_index

How can I do this?


via Yahya Uddin

Advertisement