Showing posts with label laravel. Show all posts
Showing posts with label laravel. Show all posts

Saturday, April 8, 2017

how to create helpers file laravel5

Simple tip for simple stuff.

create folder Helpers in app directory
create file StringHelper.php in app\Helpers

<?php
namespace App\Helpers;
class StringHelper
{
public static function getCleanString($string)
{
//remove unnecessary chars
$string = str_replace(['-', ' '], '', $string);
return str_slug($string);
}
}

add any simple function in this class as static.
when you need a different helper, create new class for example YoutubeHelper.php and add there stuff you need.

usage

\App\Helpers\StringHelper::getCleanString($name)

Saturday, December 31, 2016

Laravel insert ignore check if inserted (affected rows for insert ignore)

Halo guys!
if you break your head for finding solution to check if row is inserted here is the way

$query = "INSERT INTO table (id) VALUES (?)";
    try {
        DB::insert($query, array($value));
        return 1;
    } catch (\Exception $e) {
        return 0;
    }

The solution is simle - not use insert ignore. So we are catching exception instead of fatal erroring and know if it did or not.
You can even do query builder insert instead of raw query.

Monday, October 3, 2016

Laravel 5.3 Nginx Config

    server {
            listen 80;
            listen [::]:80;

            root /var/www/laravel/public;
            index index.php index.html index.htm;

            server_name my_app.dev;

            location / {
                    try_files $uri $uri/ /index.php?$query_string;
            }
            location ~ \.php$ {
              include snippets/fastcgi-php.conf;
              fastcgi_pass unix:/run/php/php7.0-fpm.sock;
            }

            location ~ /\.ht {
                deny all;
            }

Wednesday, August 31, 2016

Laravel fresh install ubuntu HTTP 500 Fix

sudo chmod 755 -R laravel_app
sudo chmod -R o+w laravel_blog/storage