josephmtinangi

josephmtinangi

Member Since 2 Years Ago

Dodoma

Web developer at Dodoma, Tanzania

Experience Points 2,150
Experience Level 1

2,850 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed 7
Lessons
Completed
Best Reply Awards 2
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

25 Apr
1 year ago

josephmtinangi left a reply on Where Are You All From?

Dodoma, Tanzania

13 Jan
1 year ago

josephmtinangi left a reply on How To Namespace Repositories With Usernames Like How Github Does

Thank you for your response

I specifically want to know about the database schema.

josephmtinangi started a new conversation How To Namespace Repositories With Usernames Like How Github Does

How to namespace repositories with usernames like how Github does. For example a repository can have the same name e.g demo but under different usernames

user1/demo
user2/demo

How to implement it in database?

19 Dec
1 year ago

josephmtinangi started a new conversation What Is Pubsubhubbub?

I came across a concept called pubsubhubbub . Can anyone explain to me what is that?

13 Oct
1 year ago

josephmtinangi started a new conversation How To Implement Database Synchronization Between Local And Remote Server

I have a web application that runs on a local server. The web app does not have an internet connection all the time. I want that when there is an internet connection it should insert the local changes to the remote database server.

01 Oct
1 year ago

josephmtinangi left a reply on Model To Model->Id Relationship

Maybe you should separate the file types for each model. i.e. you can have UserFileType and EquipmentFileType

josephmtinangi left a reply on Model To Model->Id Relationship

If that's the case, Try this

Table Structure

- users
    - name - string
    
- equipments
    - name - string
    
- file_types
    - name - string
    - file_typeable_id - integer
    - file_typeable_type - string
    

Model Structure

<?php

    namespace App;
    
    use Illuminate\Database\Eloquent\Model;
    
    /* FileType */
    class FileType extends Model
    {
        public function fileTypeable()
        {
            return $this->morphTo();
        }
    }
    
    /* User */
    class User extends Authenticatable
    {
        public function fileTypes()
        {
            return $this->morphMany('App\FileType', 'file_typeable');
        }    
    }   
    
    /* Equipment */
    class Equipment extends Model
    {
        public function fileTypes()
        {
            return $this->morphMany('App\FileType', 'file_typeable');
        } 
    }        

    

Retrieving Polymorphic Relations

For User

$user = App\User::find(1);
$fileTypes = $user->fileTypes;

For Equipment

$equipment = App\Equipment::find(1)
$fileTypes = $equipment->fileTypes;
30 Sep
1 year ago

josephmtinangi left a reply on Model To Model->Id Relationship

Hello exorion,

For your scenario, I would use polymorphic-relations. Polymorphic relations allow a model to belong to more than one other model on a single association.

Table structure

- users
    - name - string
- equipments
    - name - string
- file_types
    - name - string
- files
    - url - string
    - file_type_id - integer
    - fileable_id - integer
    - fileable_type - string
    

Two important columns to note are the fileable_id and fileable_type columns on the files table. The fileable_id column will contain the ID value of the user or equipment, while the fileable_type column will contain the class name of the owning model. The fileable_type column is how the ORM determines which "type" of owning model to return when accessing the fileable relation.

Model Structure

    <?php

        namespace App;
        
        use Illuminate\Database\Eloquent\Model;
        
        class File extends Model
        {
            public function fileable()
            {
                return $this->morphTo();
            }
        }


    <?php

        namespace App;
        
        use Illuminate\Database\Eloquent\Model;
        
        class Equipment extends Model
        {
            public function files()
            {
                return $this->morphMany('App\File', 'fileable');
            }
        }




        <?php
        
        namespace App;
        
        use Illuminate\Notifications\Notifiable;
        use Illuminate\Foundation\Auth\User as Authenticatable;
        
        class User extends Authenticatable
        {
            use Notifiable;
        
            /**
             * The attributes that are mass assignable.
             *
             * @var array
             */
            protected $fillable = [
                'name', 'email', 'password',
            ];
        
            /**
             * The attributes that should be hidden for arrays.
             *
             * @var array
             */
            protected $hidden = [
                'password', 'remember_token',
            ];
        
            public function files()
            {
                return $this->morphMany('App\File', 'fileable');
            }
        }
        
        

Retrieving Polymorphic Relations

Once your database table and models are defined, you may access the relationships via your models. For example, to access all of the files for an equipment, we can simply use the files dynamic property:

    $equipment = App\Equipment::find(1);
            
    foreach ($equipment->files as $file) {
        //
    }

You may also retrieve the owner of a polymorphic relation from the polymorphic model by accessing the name of the method that performs the call to morphTo. In our case, that is the filable method on the File model. So, we will access that method as a dynamic property:

$file = App\File::find(1);

$fileable = $file->fileable;

The fileable relation on the File model will return either a User or an Equipment instance, depending on which type of model owns the file.

Thanks

17 Sep
1 year ago

josephmtinangi left a reply on Right Way To Choose What Login Will Use;

Hello PITER_OG

If you are trying to separate users and clients and give them different access levels to system resources, I think the best way is to put all in the same table and then control their access using roles and permissions.

You can implement roles and permissions yourself or you can use a package. There are many packages out there. I recommend you to read this Laravel News post.

https://laravel-news.com/two-best-roles-permissions-packages

Thank you

josephmtinangi left a reply on Dropdown Of Estimates Returns Null

Hello JGRAVOIS

There are many ways to have an array like that, I am going to show you two ways

  1. Through a method that does not return a value
  2. Through a method that returns a value

Here we go...

1. Through a method that does not return a value

You can declare an empty array in data properties lets say estimates

new Vue({
    el: '#app',
    data: {
        estimates: []
    }
})

Then create a method that create the estimates and assign the values to that array. I am going to be pushing objects to that estimates array with attributes id and value

new Vue({
  el: '#app',
  data: {
    estimates: []
  },
  methods: {
    createEstimates: function () {
     for (i = 0; i < 6; i++) {
        this.estimates.push({
          id: i,
          value: moment().add(i, 'months').format('MMMM YYYY')
        });
      }
    }
  }
})

You can execute the createEstimates methods in any way you want. I am going to call it in mounted

new Vue({
  el: '#app',
  data: {
    estimates: []
  },
  methods: {
    createEstimates: function () {
     for (i = 0; i < 6; i++) {
        this.estimates.push({
          id: i,
          value: moment().add(i, 'months').format('MMMM YYYY')
        });
      }
    }
  },
  mounted: function() {
    this.createEstimates();
  }
})

Then in my view I am going to create a dropdown like this

<div id="app">
    <select>
      <option :value="estimate.id" v-for="estimate in estimates">
        {{ estimate.value }}
    </option>
    </select>
</div>

Here is the JSBin

http://jsbin.com/vujuha/edit?html,js,output

2. Through a method that returns a value

Everything remains as it is but change the createEstimates method to be like this

createEstimates: function () {
 let data = [];
 for (i = 0; i < 6; i++) {
    data.push({
      id: i,
      value: moment().add(i, 'months').format('MMMM YYYY')
    });
  }
  
  return data;
}

Then to execute the method

mounted: function() {
this.estimates = this.createEstimates();
}

Full source code

new Vue({
  el: '#app',
  data: {
    estimates: []
  },
  methods: {
    createEstimates: function () {
     let data = [];
     for (i = 0; i < 6; i++) {
        data.push({
          id: i,
          value: moment().add(i, 'months').format('MMMM YYYY')
        });
      }
      
      return data;
    }
  },
  mounted: function() {
    this.estimates = this.createEstimates();
  }
})

Here is the JSBin

http://jsbin.com/xirikop/edit?html,js,output

Thank you

josephmtinangi left a reply on Process Data From Pivot Table Relationships

For me, I'll do as follows,

I'll create a method called credits in the Organization model which will give me the total credits for all products the organization has purchased

public function credits()
{
    $credits = 0;
    
    foreach($this->purchases as $purchase) {
        $credits += $purchase->pivot->credits;
    }

    return $credits;
}

Then anywhere I can say $organization->credits() which will give me the total credits for all products the organization has purchased.

If I want total credits for a specific product in that organization, you can add an optional productId parameter in credits method so that you can sum the credits in that organization

Then the method will become

public function credits(Product $product = null)
{
    $credits = 0;
    
    if (!$product) {
        foreach($this->purchases as $purchase) {
            $credits += $purchase->pivot->credits;
        }

        return $credits;
    }

    foreach ($this->purchases as $purchase) {
        if ($product->id == $purchase->pivot->product_id) {
            $credits += $purchase->pivot->credits;
        }
    }       

    return $credits;
}

Then anywhere I can say $organization->credits($product) where $product is a model instance

This is the first approach I can think of though it needs a lot of refactoring but it works

16 Sep
1 year ago

josephmtinangi left a reply on Error Storage ??

Hello NUMETALSOUR,

I seems like there is a mix of file systems, Windows uses backslashes and Linux use forward slashes

From this path

C:\xampp\htdocs\infinite\storage\framework/sessions/TJ289IdqO6Po6y30QihPuTm03ApFnPxa4RvcFnJH

This is for Windows

C:\xampp\htdocs\infinite\storage\framework

And this is for Linux

/sessions/TJ289IdqO6Po6y30QihPuTm03ApFnPxa4RvcFnJH

So they cannot be mixed together

Try to double check the file paths and fix them, then it should work

josephmtinangi left a reply on Gloudemans Shoppingcart/How To Store Into The Database The Cart Data

Hello MINAUNG,

I assume that you have orders table with fields (id, product_id, customer_id, timestamps).

The gloudemans/shoppingcart package has several methods to access the shopping cart, if you want a single item with its rowId you can write Cart::get($rowId) and if you want all items this Cart::content() will give you a collection of cart items which you can iterate over.

I am going to show you two ways to store cart data into the database

  1. Storing a single item
  2. Storing all items

Here we go

  1. Storing a single item

     public function store(Request $request)
     {
         // get a single product
         $rowId = 'da39a3ee5e6b4b0d3255bfef95601890afd80709';
         $product = Cart::get($rowId);
         
         // store the product into the database
         Order::create([
             'product_id' => $product->id,
             'customer_id' => auth()->id(),
         ]);
         
         return back();
     }
     
    

Note: I have not tested the package, I hope that Cart::get($rowId) returns an object

  1. Storing all items

     public function store(Request $request)
     {
         // get all items
         $products = Cart::content();
         
         // iterate through the products and store them into the database
         foreach($products as $product){
             Order::create([
                 'product_id' => $product->id,
                 'customer_id' => auth()->id(),
             ]);
         }
         
         return back();
     }
    

josephmtinangi left a reply on Images

Hello MURALIYADAV,

If your images are stored in public/images directory and one of your images is named photo.jpg, then to access the image you can write

<img src="{{ asset('images/photo.jpg') }}" alt="">

in one of your views

josephmtinangi left a reply on Use With Two Static Function

Does it give any error message? What is the error message?

josephmtinangi left a reply on Pulling More Than One Value In Query Builder

Writing only

$items = Category::find(6)->products;

should give you products in that category

If you want to load products which has images you should write

$items = Category::find(6)->products()->whereNotNull("image")->get();

And if you want to load products which has price then write

$items = Category::find(6)->products()->whereNotNull("image")->whereNotNull("price")->get();

I think that the price column is integer or double, therefore you cannot say where("price", true)

I hope it helps

14 Sep
1 year ago

josephmtinangi left a reply on Vue Connecting To Laravel API

From the image, it seems like it is a network error. What response does it give from postman?

31 May
2 years ago

josephmtinangi started a new conversation Is There A Laravel Helper To Reverse A Slug?

For example if I have a slug called some-post and when I pass it to that helper it will return Some Post

05 Apr
2 years ago

josephmtinangi left a reply on Where Are You All From?

Dodoma, Tanzania