• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
seegatesite header

Seegatesite.com

Seegatesite.com - Programming Tutorial , Sharing , How and Learn Together

  • TOOLS
    • Bootstrap Navbar Online Generator
    • Customize Sidebar Menu Bootstrap 3
    • Bootstrap Demo
  • ADVERTISE
  • CATEGORIES
    • Android
    • Blogging Tips
    • Database
    • CSS
    • Info Gadget
    • Javascript
    • Linux
    • PHP
    • Various
    • WordPress
  • Q&A
  • PHP
  • JAVASCRIPT
  • JQUERY
  • ANGULAR
  • WORDPRESS
  • SEO
  • REACT
🏠 » PHP » How To Create Custom Class In Laravel 5.5 For Beginners

How To Create Custom Class In Laravel 5.5 For Beginners

By Sigit Prasetya Nugroho ∙ February 3, 2018 ∙ PHP ∙ Leave a Comment

Share : TwitterFacebookTelegramWhatsapp

Creating custom class on Laravel is easy to apply. Often we need additional classes to summarize and facilitate us in building applications.

Laravel is a PHP framework that implements a fairly robust MVC concept and a fairly viscous application of Object Oriented Programming. In addition, Laravel has a fairly neat encoding structure that makes the new custom class on Laravel applications to be fast and easy. Follow this short tutorial

Immediately, we begin to create a custom class laravel that will be used to store data in a database table.

How To Create Custom Class In Laravel 5.5 For Beginners Min

Table of Contents

  • 1 How to Create a Custom Class Laravel 5.5 for beginners
    • 1.1 So my short tutorial on how to create a custom class Laravel framework 5.5

How to Create a Custom Class Laravel 5.5 for beginners

1. Add a new folder inside the app folder on the Laravel project folder that we created. For example, I created a folder named CustomClass

Related Articles :

  • Basic Class in Object Oriented Programming PHP

Create Custom Class Laravel Framework

2. Add a new file in the CustomClass folder with the name record_log.php

3. Fill in the following class code in the record_log.php file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
namespace App\CustomClass;
 
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;
use Illuminate\Support\Facades\Hash;
use App\t_log;
use App\User;
class record_log
{
    public static function  save_log($token, $ket_log, $post_log)
    {
      try{
        $getuser = User::where('api_token', $token)->first();
        if(!$getuser){
          $id = 0;
        }else{
          $id =   $getuser->id_user;
        }
        try {
            $data =  t_log::create([
              'id_user'=> $id,
              'ket_log'=> $ket_log,
              'post_log'=> $post_log,
            ]);
        } catch (\Illuminate\Database\QueryException $ex) {
          //dd ($ex->getMessage());
        }
      } catch(\Illuminate\Database\QueryException $ex){
          //dd ($ex->getMessage());
      }
 
    }
}

A brief description

The above class is used to store user logs in a database every time a user performs an activity on an application system.

Don’t forget to record the namespace

1
namespace App\CustomClass;

4. To access the class as follows

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
namespace App\Http\Controllers;
 
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;
use Illuminate\Support\Facades\Hash;
use App\User;
use App\CustomClass\record_log;
 
class loginController extends Controller
{
public function login(Request $request)
    {
.......................
record_log::save_log($api_token,'access login',json_encode($request->all()));
.......................
}
}

Done, hopefully, the above tutorial can help you, beginners, to learn Laravel.

Maybe you are interested to read the article Restful API Tutorial With Lumen Laravel 5.5 For Beginners

So my short tutorial on how to create a custom class Laravel framework 5.5

Another PHP Related Post :

  • How To Replace String With Another String In PHP
  • Login Page – Tutorial CRUD Client and API Server Using JQuery And Lumen Part 2
  • Tutorial CRUD Client and API Server Using JQuery And Lumen Part 1
  • How To Solve Problems Illegal mix of collations (latin1_swedish_ci,IMPLICIT) In Laravel
  • How To Resolve No ‘Access-Control-Allow-Origin’ Header In Lumen
  • Restful API Tutorial With Lumen Laravel 5.5 For Beginners

Avatar for Sigit Prasetya Nugroho

About Sigit Prasetya Nugroho

This site is a personal Blog of Sigit Prasetya Nugroho, a Desktop developer and freelance web developer working in PHP, MySQL, WordPress.

Reader Interactions

Leave a Reply Cancel reply

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

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Welcome to my Home,

Avatar for Sigit Prasetya NugrohoThis site is a personal Blog of Sigit Prasetya Nugroho, a Desktop developer and freelance web developer working in PHP, MySQL, WordPress.



Popular Articles

Checked checkbox AdminLTE Bootstrap in Jquery

November 4, 2014 By Sigit Prasetya Nugroho 7 Comments

Simple create date format validation with jqueryUI

December 21, 2014 By Sigit Prasetya Nugroho Leave a Comment

Create Simple Progress Bar for Fake Online Generator with Jquery

January 10, 2015 By Sigit Prasetya Nugroho Leave a Comment

22+ Coolest Free Jquery Plugin For Premium Theme

October 3, 2015 By Sigit Prasetya Nugroho Leave a Comment

Easy Build Your Anti Copy Paste Plugin

October 6, 2015 By Sigit Prasetya Nugroho Leave a Comment

Popular Tags

adminlte (15) adsense (13) adsense tips (4) affiliate amazon (13) amazon (12) Android (8) angular (16) angular 4 (12) angular 5 (4) asin grabber (3) Bootstrap (27) codeigniter (5) create wordpress theme (5) crud (8) css (6) free wordpress theme (7) google adsense (4) imacros (4) increase traffic (6) jquery (34) laravel (10) laravel 5 (5) learn android (5) modal dialog (5) mysql (6) nodeJs (4) optimize seo (4) pdo (6) php (30) plugin (53) pos (7) Publisher Tips (5) react (3) Reactjs (7) SEO (37) theme (17) tutorial angular (5) tutorial angular 4 (6) tutorial javascript (10) tutorial javascript beginners (4) twitter (3) widget (3) wordpress (18) wordpress plugin (13) XMLRPC (5)




  • About
  • Contact Us
  • Disclaimer
  • Privacy Policy
  • Terms and Conditions

©2021 Seegatesite.com