Connect with us

Laravel 6.0 - 6.4 - how to fix str_slug and str_limit with any other helpers function

kizinho

Published

on

Follow
NEWS: Laravel 6.0 - 6.4 - how to fix str_slug and str_limit with any other helpers function [New  Developer] » Naijacrawl
Photo: Naijacrawl
site

Hi folks, since laravel 6.0 removed many things like make Auth and Helpers functions. Before you can use them you need to install their packages.


You can use helper function like str_slug, which is used to create a slug and str_limit, which is used to set a limit of a string. Today will you how you can make use of it by just installing a package for helper function


composer require laravel/helpers

That's all you need and start using the helper functions like you are doing on laravel 5.


Thanks for reading

site


kizinho

I am a software developer, like meeting people and love blogging, that's why I developed naijacrawl because that's what I love doing.

Continue Reading
Click To Comment

BE First To Comment


    Leave a Reply

    Your email address will not be published. Required fields are marked *

    Easy way to Host your Laravel Application on Shared Hosting

    kizinho

    Published

    on

    DEVELOPER PROGRAMMING: Easy way to Host your Laravel Application on Shared Hosting [New  Developer Programming] » Naijacrawl
    Photo: Naijacrawl

    Hi , Folks have you finished building that your awesome project but hosting it o shared hosting is what remains, don't worry you are on the right track, I have the best way to do that.

    Steps

    1. Create Database on your online cpanel
    2. Upload your project or use git to do that
    3. Set everything up on your ENV
    4. now we need .htaccess that you will create inside your laravel root folder


    Inside the .htaccess add this code

    RewriteEngine On#endsRewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$
    RewriteCond %{REQUEST_URI} !^/public/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /public/$1RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$
    RewriteRule ^(/)?$ public/index.php [L]

    Replace with your domain

    What this code does is that when you host your laravel application and access it, it will show the user the original folder of your project, unless you go to the public before it can load the project as a web but now enjoy hosting with shared hosting after following the above steps.

    Enjoy and share

    Continue Reading

    Upload files to Amazon S3 from the browser using pre-signed post (Laravel, Vue.js/Nuxt.js)

    kizinho

    Published

    on

    DEVELOPER PROGRAMMING: Upload files to Amazon S3 from the browser using pre-signed post (Laravel, Vue.js/Nuxt.js) [New  Developer Programming] » Naijacrawl
    Photo: Naijacrawl

    Upload files to Amazon S3 from the browser using pre-signed post (Laravel, Vue.js/Nuxt.js)

    This article was written by Okonkwo Buchi Flair a ccolleague of mind, read and know how to simply upload your files via Amazon S3.

    original article can be found here

    Before I begin I would love to point out that is my first post so please pardon me any errors you may find as you read along


    Recently I’ve been working on a e-learning platform which of course was going to deal with a lot of uploads and letting the server handle all that will be quite… 😫 And so I had to find an alternative which was direct uploads from the browser. I hit Google search and boy! there were tons of info but then they all made use of javascript, the ones with php used html forms. However, in this post we won’t be using html form. we’ll be making use of axios.

    This post assumes you’ve set up your s3 bucket and is fully focused on how to get your uploads working. Don’t forget your CORS configuration as well.


    First add your bucket details to your .env file and don’t forget to restart when you make changes to your .env file

    AWS_ACCESS_KEY_ID=xxxxxxV2HQFVM
    AWS_SECRET_ACCESS_KEY=xxxxxx+xxxx+xxxx+xxxxx
    AWS_DEFAULT_REGION=eu-west-2
    AWS_BUCKET=Your-Bucket-Name
    

    Next install aws sdk by running the following code

    composer require aws/aws-sdk-php-laravel
    

    Create a controller that’s going to take care of your uploads. Meanwhile the filesystem configuration file located at config/filesystem.php is already set up by default to help you access your S3 configurations in the .env file

    use Aws\S3\PostObjectV4;
    use Aws\S3\S3Client;
    
    class MyController extends Controller
    {
    public function upload(Request $request)
    {
    $filename =  $request->filename;
    $directory =  $request->directory;
    $s3 = config('filesystems.disks.s3');
    $client = new S3Client(['version' => 'latest','region' => $s3['region'],'credentials' => ['key' => $s3['key'],'secret' => $s3['secret'],
    ]]);
    $bucket = $s3['bucket'];
    $prefix = $directory . '/';
    $acl = 'public-read';
    $expires = '+10 minutes';
    $formInputs = [
     'acl' => $acl,
     'key' => $prefix . $filename,
    ];
    $options = [
     ['acl' => $acl],
     ['bucket' => $bucket],
     ['starts-with', '$key', $prefix],
    ];
    $postObject = new PostObjectV4($client, $bucket, $formInputs, $options, $expires);
    $attributes = $postObject->getFormAttributes();
    $inputs = $postObject->getFormInputs();
    return response(['attributes' => $attributes, 'inputs' => $inputs, 'url' => $attributes['action'] . '/' . $directory . '/' . $filename]);
    }
    }
    

    So let me explain what’s happening in the above code. From my frontend I am going to make a post request which would contain the name of the file (just as it would be in my s3 bucket and also the folder where it’s going to be saved since my files are going to be saved in different folders. I get my s3 configurations from the env file use s3 file configuration in the config/filesystem.php file. The rest are self explanatory I hope. The $attributes contains information like the form action which is going to look like https://your-bucket-url. Yours won’t necessary have a directory of course. The ‘url’ in my return is what I intend to save in my database once my upload is successful and it would look like this https://bucket-url/directory/filename. With this you will be able successfully generate a presigned POST.

    Next create a post route that points to the controller. Since I am making use of Lumen my route looks like this

    $router->post(‘uploads/store’, ‘[email protected]’);
    

    Next we’ll dive into the frontend part where we’ll be submitting a form with the detailed generated above.

    In my Nuxt file I created a component S3FileUploads.vue that looked like this

    I am going to attach screenshots instead for some codes.

    I have a computed property which basically returns the file extension

    computed property get file extension

    I also have a method for generating random strings

    random string generator

    I like to have a general file or files where my endpoints are. It makes it easier to make changes. So I have an endpoint which points to the controller that generates the presigned post for me.

    And then I have my upload file method. The first part of this method involved me trying to generate a unique name for my files and

    There was an issue I encountered while trying send the file to my s3 with axios. My header already contained an Authorization token which made the s3 reject the request, and I couldn’t remove the Authorization because of course I can’t access the backend if my request doesn’t contain the token. So removing it wasn’t an option. Th alternative for me was to use the fetch

    Of course there were other things I did like store the file url to the database if the upload was successful. That’s basically it. Feel free to ask any questions, I’ll try to reply them, and I’d really appreciate those claps too. Thanks for reading

    Continue Reading

    How to Integrate Flutterwave Rave Payment System in your Laravel Applications

    kizinho

    Published

    on

    DEVELOPER PROGRAMMING: How to Integrate Flutterwave Rave Payment System in your Laravel Applications [New  Developer Programming] » Naijacrawl
    Photo: Naijacrawl

    Hi Folks, I know many laravel developers that have been using Paystack as their payment system have been finding it difficult to integrate Paystack Laravel Package from Laravel 6.0 - 7.0 versions. Today I have a beautiful solution by using Flutterwave Rave Payment System, this process will work on any laravel versions.

    Requirements

    1. Running Exiting Project on Laravel
    2. Create Account on Flutterwave
    3. Then you are good to go

    Lets Begin

    composer require kingflamez/laravelrave
    

    Once Flutterwave Rave for Laravel is installed, you need to register the service provider. Open up config/app.php and add the following to the providers key.

    'providers' => [
     /* * Package Service Providers... */
     ... 
    KingFlamez\Rave\RaveServiceProvider::class, 
    ...
    ]
    

    Also add this to the aliases

    'aliases' => [
     ... 
    'Rave' => KingFlamez\Rave\Facades\Rave::class, 
    ...
    ]
    

    Configuration

    Publish the configuration file using this command:

    php artisan vendor:publish
     --provider="KingFlamez\Rave\RaveServiceProvider"

    Usage

    Open your .env file and add your public key, secret key, environment variable and logo url like so:

    RAVE_PUBLIC_KEY=FLWPUBK_TEST
    -xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-X
    RAVE_SECRET_KEY=FLWSECK_TEST-xxxxxxxxxxxxxxx
    xxxxxxxxxxxxxxx-XRAVE_TITLE="Naijacrawl"
    RAVE_ENVIRONMENT="staging"
    RAVE_LOGO="https://rave.flutterwave.com/
    static/img/[email protected]"
    RAVE_PREFIX="rave"
    • RAVE_PUBLIC_KEY - This is the api public key gotten from your dashboard (compulsory)
    • RAVE_SECRET_KEY - This is the api secret key gotten from your dashboard (compulsory)
    • RAVE_TITLE - This is the title of the modal (optional)
    • RAVE_ENVIRONMENT - This can be staging or live. Staging API keys can be gotten here while live API keys can be gotten here (compulsory)
    • RAVE_LOGO - This is a custom logo that will be displayed on the modal (optional)
    • RAVE_PREFIX - This is a the prefix added to your transaction reference generated for you (optional)
    • SECRET_HASH - This is the secret hash for your webhook, this is necessary if you are setting up a recurrent payment


    1. Setup Routes


    Route::post('/pay', '[email protected]')
    ->name('pay');
    Route::post('/rave/callback',
     '[email protected]')->name('callback');
    


    2. Grant CSRF Access to Rave Callback


    Go to app/Http/Middleware/VerifyCsrfToken.php 

    and add your callback url to the $except array

    protected $except = [ 'rave/callback'];
    

    A sample form from your frontend will look like so:

    @php
    $array = array(array(
    'metaname' => 'color',
     'metavalue' => 'blue'),
     array('metaname' => 'size',
     'metavalue' => 'big'));
    @endphp
    
    "POST" action="{{ route('pay') }}" id="paymentForm"> {{ csrf_field() }} type="hidden" name="amount" value="500" />type="hidden" name="payment_method" value="both" />type="hidden" name="description" value="Beats by Dre. 2017" />type="hidden" name="country" value="NG" />type="hidden" name="currency" value="NGN" />type="hidden" name="email" value="[email protected]" />type="hidden" name="firstname" value="Oluwole" />type="hidden" name="lastname" value="Adebiyi" />type="hidden" name="metadata" value="{{ json_encode($array) }}" >type="submit" value="Buy" />

    In this implementation, we are expecting a form encoded POST request to this script. The request will contain the following parameters.

    • payment_method Can be card, account, both
    • description Your transaction description
    • logo Your logo url
    • title Your transaction title
    • country Your transaction country
    • currency Your transaction currency
    • email Your customer's email
    • firstname Your customer's firstname
    • lastname Your customer's lastname
    • phonenumber Your customer's phonenumber
    • ref Your transaction reference.
    • It must be unique per transaction.
    • By default, the Rave class generates
    • a unique transaction reference for each
    • transaction. Pass this parameter only if
    • you uncommented the related section in
    • the script below.

    3. Setup your Controller

    Setup your controller to handle the routes. I created the RaveController.

    Use the Rave facade.


    Example


    namespaceApp\Http\Controllers;
    use Illuminate\Http\Request;
    //use the Rave Facadeuse Rave;class RaveController extends Controller{ 
    /** * Initialize Rave payment process * @return void */ 
    public function initialize() {
     //This initializes payment and redirects to the payment gateway 
    //The initialize method takes the parameter of the redirect URL
     Rave::initialize(route('callback')); 
    } 
    /** * Obtain Rave callback information 
    * @return void */public function callback() {
     $data =Rave::verifyTransaction(request()->txref);
    dd($data); 
    // view the data response 
     if ($data->status == 'success') {
     //do something to your database
    }else
     {
    //return invalid payment
    }
     }
    }
    



    Continue Reading

    Latest