<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Victor Yunusa</title>
    <description>The latest articles on DEV Community by Victor Yunusa (@victoryunusa).</description>
    <link>https://dev.to/victoryunusa</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F122382%2F5b6d966d-6454-4bf2-b81e-2f602f72d631.jpeg</url>
      <title>DEV Community: Victor Yunusa</title>
      <link>https://dev.to/victoryunusa</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/victoryunusa"/>
    <language>en</language>
    <item>
      <title>Building a campus marketplace using Laravel and Cloudinary</title>
      <dc:creator>Victor Yunusa</dc:creator>
      <pubDate>Tue, 18 Dec 2018 15:12:39 +0000</pubDate>
      <link>https://dev.to/victoryunusa/building-a-campus-marketplace-using-laravel-and-cloudinary-5ala</link>
      <guid>https://dev.to/victoryunusa/building-a-campus-marketplace-using-laravel-and-cloudinary-5ala</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fdst2ry3yfoaayu121bjy.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fdst2ry3yfoaayu121bjy.PNG" title="Logo Title Text 1" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On December 1, I participated in the HACK-API hackathon, sponsored by Cloudinary, in Accra, Ghana. The aim of the hackathon was to make the Cloudinary API known to the Ghanaian technology ecosystem. For our hackathon project, my team and I built a marketplace app for college campuses. Our purpose was twofold: to raise the awareness for the small businesses that operate within the campus and to make it easy for people to find certain products and services.&lt;/p&gt;

&lt;p&gt;At the outset, our first priority was to locate a package that would facilitate the storage of the app’s images and videos on Cloudinary. Gratifyingly, after a thorough search on Github, I found Laravel, a framework of the PHP programming language, which fit the bill and with which we then developed the app’s back end. It was a smooth sail.&lt;/p&gt;

&lt;p&gt;Read on for a step-by-step rundown of the development process.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Install Laravel
&lt;/h2&gt;

&lt;p&gt;To install Laravel, follow the procedure on its site. After installation, set up your &lt;code&gt;.env&lt;/code&gt; variables, go to the installation folder, and follow the steps below:&lt;/p&gt;

&lt;p&gt;Run this command to create an authentication scaffolding, for example, the login and registration pages:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;php artisan make:auth&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Run this command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;php artisan serve&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The following output is then displayed, which shows that the server is currently running:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Laravel development server started: http://127.0.0.1:8000&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Go to the URL on your browser.&lt;/p&gt;

&lt;p&gt;The home page is then displayed:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Ffn9tlo9sfk0vnhpmu9by.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Ffn9tlo9sfk0vnhpmu9by.PNG" title="Login Page" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click LOGIN in the upper right corner for the Login page:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fs4gi73tktkcjy18zpzsm.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fs4gi73tktkcjy18zpzsm.PNG" title="Login Page" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Create Models and Migration for the Marketplace App
&lt;/h2&gt;

&lt;p&gt;The marketplace app needs the following tables in the database:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;User table (already created at the beginning)&lt;/li&gt;
&lt;li&gt;Product table&lt;/li&gt;
&lt;li&gt;Category table&lt;/li&gt;
&lt;li&gt;Comments table&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To create migration files for the products, category, and comments tables, run these three commands in the order listed:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;php artisan make:migration create_products_table&lt;/code&gt;&lt;br&gt;
&lt;code&gt;php artisan make:migration create_categories_table&lt;/code&gt;&lt;br&gt;
&lt;code&gt;php artisan make:migration create_comments_table&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Afterwards, go to the &lt;code&gt;database/migrations&lt;/code&gt; folder for the migration files, You will see a list of the files you just created and the ones that were automatically created by Laravel.&lt;br&gt;
Open the &lt;code&gt;products&lt;/code&gt; migration file in a text editor and copy and paste the following code for the &lt;code&gt;up&lt;/code&gt; function as the file content:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;public function up()&lt;br&gt;
    {&lt;br&gt;
        Schema::create('products', function (Blueprint $table) {&lt;br&gt;
            $table-&amp;gt;increments('id');&lt;br&gt;
            $table-&amp;gt;integer('user_id');&lt;br&gt;
            $table-&amp;gt;string('product_name');&lt;br&gt;
            $table-&amp;gt;integer('category');&lt;br&gt;
            $table-&amp;gt;string('price');&lt;br&gt;
            $table-&amp;gt;text('description')-&amp;gt;nullable();&lt;br&gt;
            $table-&amp;gt;text('image');&lt;br&gt;
            $table-&amp;gt;timestamps();&lt;br&gt;
        });&lt;br&gt;
    }&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Do the same for the &lt;code&gt;categories&lt;/code&gt; and &lt;code&gt;comment&lt;/code&gt; migration files:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;public function up()&lt;br&gt;
    {&lt;br&gt;
        Schema::create('categories', function (Blueprint $table) {&lt;br&gt;
            $table-&amp;gt;increments('id');&lt;br&gt;
            $table-&amp;gt;string('category');&lt;br&gt;
            $table-&amp;gt;timestamps();&lt;br&gt;
        });&lt;br&gt;
    }&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;public function up()&lt;br&gt;
    {&lt;br&gt;
        Schema::create('comments', function (Blueprint $table) {&lt;br&gt;
            $table-&amp;gt;increments('id');&lt;br&gt;
            $table-&amp;gt;integer('user_id');&lt;br&gt;
            $table-&amp;gt;integer('product_id');&lt;br&gt;
            $table-&amp;gt;string('comment');&lt;br&gt;
            $table-&amp;gt;timestamps();&lt;br&gt;
        });&lt;br&gt;
    }&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 3: Install the Laravel Package for Cloudinary
&lt;/h2&gt;

&lt;p&gt;As reference, see the documentation for the Laravel package on Github.&lt;/p&gt;

&lt;p&gt;Do the following:&lt;/p&gt;

&lt;p&gt;Run this command to install the dependencies required by Cloudinary:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;composer require jrm2k6/cloudder&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Edit your &lt;code&gt;.env&lt;/code&gt; file to add the following information from Cloudinary:    &lt;/p&gt;

&lt;p&gt;Required&lt;br&gt;
&lt;code&gt;CLOUDINARY_API_KEY=012345679890123&lt;br&gt;
CLOUDINARY_API_SECRET=foobarfoobarfoob-arfoobarfo&lt;br&gt;
CLOUDINARY_CLOUD_NAME=foobarcorp&lt;/code&gt;&lt;br&gt;
Optional&lt;br&gt;
&lt;code&gt;CLOUDINARY_BASE_URL&lt;br&gt;
CLOUDINARY_SECURE_URL&lt;br&gt;
CLOUDINARY_API_BASE_URL&lt;/code&gt;&lt;br&gt;
Because Laravel 5.5+ features Package Auto-Discovery, you need not manually add the service provider (&lt;code&gt;ServiceProvider&lt;/code&gt;). To bypass auto-discovery, add the following code to the &lt;code&gt;config/app.php&lt;/code&gt; file:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;'providers' =&amp;gt; array(&lt;br&gt;
  JD\Cloudder\CloudderServiceProvider::class,&lt;br&gt;
);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;'aliases' =&amp;gt; array(&lt;br&gt;
  'Cloudder' =&amp;gt; JD\Cloudder\Facades\Cloudder::class,&lt;br&gt;
);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Finally, run this command:&lt;br&gt;
&lt;code&gt;php artisan vendor:publish --provider="JD\Cloudder\CloudderServiceProvider"&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 4: Create Controllers
&lt;/h2&gt;

&lt;p&gt;Laravel offers a unique way of generating fast and simple controllers. Just run the following command:&lt;br&gt;
    &lt;code&gt;Php artisan make:controller ProductsController&lt;/code&gt;&lt;br&gt;
Note: Be sure to initial-capitalize the name of the controller: &lt;code&gt;Php&lt;/code&gt;.&lt;br&gt;
Repeat the same command for categories and comments. &lt;br&gt;
Next, go to the &lt;code&gt;app/Http/Controllers&lt;/code&gt; folder for your controller files. Add the following code to the &lt;code&gt;ProductsController.php&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php

    namespace App\Http\Controllers;
    use Illuminate\Http\Request;
    use App\User;
    use Hash;
    use Session;
    use Validator;
    use Illuminate\Support\Facades\Input;
    use DB;
    use Auth;
    use Cloudder;

    class ProductsController extends Controller
    {

     //This function handles the add listing page.

        public function Index(){

            return view('add');
        }
     // This function saves the form data to the database.

     public function save(Request $request)
         {

            $pic = $request-&amp;gt;file('file');
            $name = trim($request['name']);
            $price = trim($request['price']);
            $category = trim($request['category']);
            $description = trim($request['description']);

            $upload = Cloudder::upload($pic);

            if($upload){

                $picId = Cloudder::getPublicId();

                DB::table('products')-&amp;gt;insert([ 
                    'item_name'  =&amp;gt; $name,
                    'description'=&amp;gt; $description,
                    'price'      =&amp;gt; $price,
                    'category'   =&amp;gt; $category,
                    'user_id'    =&amp;gt; Auth::user()-&amp;gt;id,
                    'image'      =&amp;gt; $picId,
                 ]);

            }

            return redirect()-&amp;gt;intended("add-listing");

        }

            //This function displays the items on the product-listing page.

        public function listings(){

            $data['products'] = DB::table('products')-&amp;gt;get();
            return view('listings', $data);
        }

            //This function displays a single item in detail.

        public function details($id){

           $data['products'] = DB::table('products')-&amp;gt;where('id', "=", $id)-&amp;gt;first();
            return view('details', $data);
        }

} 

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step Five: Create Views
&lt;/h2&gt;

&lt;p&gt;Laravel is a Model View Controller (MVC) framework. We touched on models and controllers earlier and will now show you how to create views by means of Laravel’s amazing templating engine, called Blade.&lt;/p&gt;

&lt;p&gt;Go to the &lt;code&gt;resources/views&lt;/code&gt; folder and create a new file called &lt;code&gt;add.blade.php&lt;/code&gt; with the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    @extends('layouts.app')

    @section('content')
    &amp;lt;div class="container"&amp;gt;
    &amp;lt;div class="row justify-content-center"&amp;gt;
        &amp;lt;div class="col-md-8"&amp;gt;
            &amp;lt;div class="card"&amp;gt;
                &amp;lt;div class="card-header"&amp;gt;Add new product&amp;lt;/div&amp;gt;

                &amp;lt;div class="card-body"&amp;gt;
                    &amp;lt;form method="POST" action="{{ url('save-item') }}" enctype="multipart/form-data"&amp;gt;
                        @csrf

                        &amp;lt;div class="form-group row"&amp;gt;
                       &amp;lt;label for="name" class="col-md-4 col-form-label text-md-right"&amp;gt;Product Name&amp;lt;/label&amp;gt;

                            &amp;lt;div class="col-md-6"&amp;gt;
                                &amp;lt;input id="name" type="text" class="form-control{{ $errors-&amp;gt;has('name') ? ' is-invalid' : '' }}" name="name" value="{{ old('name') }}" required autofocus&amp;gt;

                                @if ($errors-&amp;gt;has('name'))
                                    &amp;lt;span class="invalid-feedback" role="alert"&amp;gt;
                                        &amp;lt;strong&amp;gt;{{ $errors-&amp;gt;first('name') }}&amp;lt;/strong&amp;gt;
                                    &amp;lt;/span&amp;gt;
                                @endif
                            &amp;lt;/div&amp;gt;
                        &amp;lt;/div&amp;gt;

                        &amp;lt;div class="form-group row"&amp;gt;
                            &amp;lt;label for="email" class="col-md-4 col-form-label text-md-right"&amp;gt;Category&amp;lt;/label&amp;gt;

                            &amp;lt;div class="col-md-6"&amp;gt;
                                &amp;lt;select class="form-control{{ $errors-&amp;gt;has('email') ? ' is-invalid' : '' }}" name="email"  required&amp;gt;
                                  &amp;lt;option&amp;gt;&amp;lt;/option&amp;gt;

                                &amp;lt;/select&amp;gt;

                                @if ($errors-&amp;gt;has('email'))
                                    &amp;lt;span class="invalid-feedback" role="alert"&amp;gt;
                                        &amp;lt;strong&amp;gt;{{ $errors-&amp;gt;first('email') }}&amp;lt;/strong&amp;gt;
                                    &amp;lt;/span&amp;gt;
                                @endif
                            &amp;lt;/div&amp;gt;
                        &amp;lt;/div&amp;gt;

                        &amp;lt;div class="form-group row"&amp;gt;
                            &amp;lt;label for="password" class="col-md-4 col-form-label text-md-right"&amp;gt;Price&amp;lt;/label&amp;gt;

                            &amp;lt;div class="col-md-6"&amp;gt;
                                &amp;lt;input id="password" type="text" class="form-control{{ $errors-&amp;gt;has('password') ? ' is-invalid' : '' }}" name="price" required&amp;gt;

                                @if ($errors-&amp;gt;has('password'))
                                    &amp;lt;span class="invalid-feedback" role="alert"&amp;gt;
                                        &amp;lt;strong&amp;gt;{{ $errors-&amp;gt;first('password') }}&amp;lt;/strong&amp;gt;
                                    &amp;lt;/span&amp;gt;
                                @endif
                            &amp;lt;/div&amp;gt;
                        &amp;lt;/div&amp;gt;

                        &amp;lt;div class="form-group row"&amp;gt;
                            &amp;lt;label for="password-confirm" class="col-md-4 col-form-label text-md-right"&amp;gt;Description&amp;lt;/label&amp;gt;

                            &amp;lt;div class="col-md-6"&amp;gt;
                                &amp;lt;textarea id="password-confirm" type="text" class="form-control" name="description" required&amp;gt;&amp;lt;/textarea&amp;gt;
                            &amp;lt;/div&amp;gt;
                        &amp;lt;/div&amp;gt;

                        &amp;lt;div class="form-group row"&amp;gt;
                            &amp;lt;label for="password-confirm" class="col-md-4 col-form-label text-md-right"&amp;gt;Image&amp;lt;/label&amp;gt;

                            &amp;lt;div class="col-md-6"&amp;gt;
                                &amp;lt;input id="password-confirm" type="file" class="form-control" name="image" required&amp;gt;
                            &amp;lt;/div&amp;gt;
                        &amp;lt;/div&amp;gt;

                        &amp;lt;div class="form-group row mb-0"&amp;gt;
                            &amp;lt;div class="col-md-6 offset-md-4"&amp;gt;
                                &amp;lt;button type="submit" class="btn btn-primary"&amp;gt;
                                    {{ __('Register') }}
                                &amp;lt;/button&amp;gt;
                            &amp;lt;/div&amp;gt;
                        &amp;lt;/div&amp;gt;
                    &amp;lt;/form&amp;gt;
                &amp;lt;/div&amp;gt;
            &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
@endsection

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is what the page looks like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fwtwv2hfoobbr7h0bsv3u.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fwtwv2hfoobbr7h0bsv3u.PNG" title="Logo Title Text 1" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Conclusion&lt;br&gt;
I hope this article has familiarized you with the Laravel framework and a few of Cloudinary’s robust capabilities and that you’re impressed by them. Do apply what you’ve learned to build other useful apps. Enjoy the fun!&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
