vendredi 3 mars 2017

Rearrange columns in a Laravel migration file

How do I re-arrange a column in a Laravel migration file for a MySQL database?

So far I have the following:

$table->date('foo')->after('bar')->change();

However, it does not seem to re-arrange the column.

Why not and how can I fix this?



via Chebli Mohamed

laravel Expected response code 250 but got code "530"

Im trying to Mail in Laravel 5.1

my mail.php code is

 return [
     'driver' => env('MAIL_DRIVER', 'smtp'),
     'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
     'port' => env('MAIL_PORT', 587),
     'from' => ['address' => 'myemail@gmail.com', 'name' => 'sample'],
     'encryption' => env('MAIL_ENCRYPTION', 'tls'),
     'username' => env('MAIL_USERNAME'),
     'password' => env('MAIL_PASSWORD'),
     'sendmail' => '/usr/sbin/sendmail -bs',
     'pretend' => env('MAIL_PRETEND', false),

 ];

my .env file is

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=myemail@gmail.com
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=null

my function to email is

public function sendEmailVerification()
{
    $user = $this->user;//retrieved by $request->user() in __construct

    Mail::send('emails.verifyemail', ['user' => $user], function ($m) use ($user) {
        $m->from('myemail@gmail.com, 'sample');

        $m->to($user->email, $user->name)->subject('Verify Email');
    });
}

Expected response code 250 but got code "530", with message "530 5.7.0 Must issue a STARTTLS command first. l188sm21749863pfl.28 - gsmtp" error appears every time i call my function.



via Chebli Mohamed

jeudi 2 mars 2017

Method save does not exist occur after lockForUpdate Laravel 5.1

Laravel Cannot Save data to DB after Pessimistic Locking

I am facing the problem that cannot update data to db while using save method with Laravel 5.1.

I am trying to update data with locking to avoid concurrency data and below is my code.

Please help me.

namespace App\Model;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
class Recharge extends Model
{
public function processSuccess($orderId, $type, $amount) {
        $query = [
            ['status', '<=', 1],
            ['order_abm', '=', $orderId],
            ['type', '=', $type],
            ['amount', '=', $amount],
        ];

        \DB::beginTransaction();
        $concur_up = Recharge::where($query)->lockForUpdate()->get();
        $concur_up->status = 5;
        $concur_up->amounted = $amount;
        $concur_up->date    = time();
        $res =$concur_up->save();
        if (!$res) {
            return "fail";
        }
        \DB::commit();
        return true;
    }
}

error shown in my editor

enter image description here

error shown in my browser

enter image description here

My using table

enter image description here



via Chebli Mohamed

I Think there is a Bug with Laravel 5.4?

i'm trying to send a email with Attachment File , It Work Perfectly when i'm using an externale link like :

public function build() 
{ return $this->view('email.test') ->attach("http://ift.tt/2ljrDaY"); }

But when i try to send Files that stored on my Storage Folder like :

public function build() 
{ return $this->view('email.test') ->attach("http://ift.tt/2lF2Jyr"); }

, it Thrown an Eroor :

Swift_IoException in FileByteStream.php line 144: Unable to open file for reading

i had already generated a Storage:LINK , that allow to me to access to Storage Folder and i can access to it via url ( http://ift.tt/2ljrCnq ) ,

Please Help me What should i do ? it's been 3 days i'm trying to resolve this problem and nothing Found :/



via Chebli Mohamed

mercredi 1 mars 2017

how get views number for my website in laravel 5.1?

my code : but always views number are 1 public function getLandPage() {

    if(is_null(Session::get('views_number'))){
        Session::put('views_number',1);
    }else{
        $c=Session::get('views_number');
        $c++;
        Session::put('views_number',$c);
    }

    return dd( Session::get('views_number'));
}



via Chebli Mohamed

Laravel blank white screen after modification

My laravel site working well. But after modification i faced with a blank white screen and no logs.

If I run below command :

php -cli artisan clear-compiled

I have this error :

Fatal error: Uncaught exception 'ReflectionException' with message 'Class log does not exist' in /data/devPhp/workspace/adhesion/vendor/laravel/framework/src/Illuminate/Container/Container.php:734 Stack trace: #0 /data/devPhp/workspace/adhesion/vendor/laravel/framework/src/Illuminate/Container/Container.php(734): ReflectionClass->__construct('log') #1 /data/devPhp/workspace/adhesion/vendor/laravel/framework/src/Illuminate/Container/Container.php(629): Illuminate\Container\Container->build('log', Array) #2 /data/devPhp/workspace/adhesion/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(697): Illuminate\Container\Container->make('log', Array) #3 /data/devPhp/workspace/adhesion/vendor/laravel/framework/src/Illuminate/Container/Container.php(849): Illuminate\Foundation\Application->make('Psr\Log\LoggerI...') #4 /data/devPhp/workspace/adhesion/vendor/laravel/framework/src/Illuminate/Container/Container.php(804): Illuminate\Container\Container->resolveClass(Object(ReflectionParameter)) #5 /data/devPhp/workspac in /data/devPhp/workspace/adhesion/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 734



via Chebli Mohamed

TokenMismatchException in VerifyCsrfToken.php line 53

i made a page view/maessage.php
http://ift.tt/1yCEpkO">

  <script>
     function getMessage(){
        $.ajax({
           type:'POST',
           url:'/getmsg',
           data:{'_token': ''},
           success:function(data){
              $("#msg").html(data.msg);
           }
        });
     }
  </script>   
  <body>
   <div id = 'msg'>This message will be replaced using Ajax. 
     Click the button to replace the message.</div>
  <?php
     echo Form::button('Replace Message',['onClick'=>'getMessage()']);
  ?>
  </body>

in routes.php

Route::get('/ajax',function(){
  return view('message');
});

Route::post('/getmsg','AjaxController@index');

in AjaxController.php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class AjaxController extends Controller
{
   public function index(){
  $msg = "This is a simple message.";
  return response()->json(array('msg'=> $msg), 200);
   }
}

when i ran http://localhost:8000/ajax http://localhost:8000/getmsg generate below error

Whoops, looks like something went wrong.

1/1 MethodNotAllowedHttpException in RouteCollection.php line 218: in RouteCollection.php line 218 and buch of error.....

but when i saw in consol it show below error TokenMismatchException in VerifyCsrfToken.php line 53: in VerifyCsrfToken.php line 53

i can't understand error .i am fresher in laravel. and i aactually don't know the meaning of '_token': '' in message.php. pls. help to solve this error.



via Chebli Mohamed