lundi 30 avril 2018

Migration doesn't update database

I have this simple code which when I run - it does not do anything at all. When I migrate, the migration runs - I have feedback from console: Migrated..... But the database stays the same. In migrations table I see my migration, also with a correct batch.

<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddDateToProgram extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('schedules', function(Blueprint $table) {
            $table->string('day')->default('2018-05-24')->nullable();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('schedules', function(Blueprint $table) {
            $table->dropIfExists('day');
        });
    }
}



via Chebli Mohamed

Which is the best folder to store the images/files in Laravel?

Which is the best folder to store the images/files on server in Laravel ? Public or Storage?



via Chebli Mohamed

samedi 28 avril 2018

Laravel 5.1 Guzzle - Undefined offset: 0

I need to access an API so I use guzzle6 and I write a function:

public function test()
    {

$client = new GuzzleHttp\Client(['defaults' => ['verify' => false]]);

try {
$res = $client->post('https://example.com/api/v2/oauth/token?grant_type=client_credentials', [
    'headers' => [
        'Content-Type' => 'application/x-www-form-urlencoded',
    ],

    'auth' => [
        'Username' => 'user_5639',
        'Password' => 'pass_asdhbas67yausihd7qaw8'
]
            ]);

$res = json_decode($res->getBody()->getContents(), true);
}

catch (GuzzleHttp\Exception\ClientException $e) {
        $response = $e->getResponse();
        $result =  json_decode($response->getBody()->getContents());

    return response()->json(['data' => $result]);
}

    }

but I got error:

ErrorException in Client.php line 346: Undefined offset: 0

When I try at POSTMAN the same request everything is fine: enter image description here

How to solve my problem?



via Chebli Mohamed

vendredi 27 avril 2018

Laravel 5.1/5.6 How to send a url in email blade

I am using Mail::send function to send emails to my end users with dynamically generated links in them Below is my sample code for the function - $myemail = "some email adderess"; $myurl = "some url that will be emailed";

Mail::send('emails.mybladetemplate', ['myemail' => $myemail] , function ($message) use ($myemail){

$message->subject('Your favorite links');
$message->from('someone@company.com', 'Company');
$message->to($myemail);
});

I am having trouble passing $myurl to the blade template and publishing it. I even used HTML in my blade template but no success. I have tested Mail::send with other templates and it works fine. Just not when I pass the variables.



via Chebli Mohamed

jeudi 26 avril 2018

what this mean : 'middleware' => 'auth:api'],

When i use in my progame Route::group(['prefix' => 'api/v1', 'middleware' => 'auth:api'], function () { doesn't works . All users can't access for open my project and i added column in table user.



via Chebli Mohamed

mercredi 25 avril 2018

ReflectionException in Route.php line 280: Class App\Http\Controllers\api/v1\SiteController does not exist

I want to immerge two laravel projects so they can have the same authentication,once i login in the first, the second will also login. The first laravel project works with API_Token, so i'm trying to add it in the second project. Since i have the two projects working with laravel 5.2 i followed the next steps: I added a column called api_token to users table - I added a route group where i placed only the dashboard just for test

  Route::group(['prefix' => 'api/v1', 'middleware' => 'auth:api'], function () {
    Route::post('/dashboard', 'SiteController@getDashboard');
});



via Chebli Mohamed

How to change different header for various pages in laravel

I need call different header for hosting and about pages mentioned below, while executing the below code I'm getting error as "Undefined class constant 'hosting'". suggest me how to solve this and call different headers for various pages.

@if(Route::hosting == 'hosting')
{
  @include('partials.header');
}
@elseif(Route::About == 'About'){
   @include('partials.header1');
}
 @endif



via Chebli Mohamed