wardaddy

Experience

1,570

0 Best Reply Awards

  • Member Since 8 Months Ago
  • 0 Lessons Completed
  • 2 Favorites

18th February, 2018

wardaddy left a reply on Add Status When Entering Data To Database • 4 months ago

solved

UserController

    public function store(Request $request)
    {
        $errors = $this->validate(request(), [
            'name' => 'required|string|min:3|max:40',
            'email' => 'required|string|email|max:40|unique:users',
            'username' => 'required|string|min:6|max:20|alpha_dash|unique:users',
            'password' => 'required|string|min:6|max:40',
        ]);

        User::create([
            'type_id' => request('user_type'),
            'name' => request('name'),
            'email' => request('email'),
            'username' => request('username'),
            'password' => bcrypt(request('password')),
        ]);

        return back()->with('status', 'Successfully Created');
    }

users.blade.php

    <script>
        @if ($errors->any())
        $(document).ready(function() {
              M.toast({
                html: 'Not Successfully Created',
                displayLength: '10000'
              });
            });
        @elseif (session('status'))
            $(document).ready(function() {
              M.toast({
                html: '{{ session('status') }}',
                displayLength: '10000'
              });
            });
        @endif
    </script>

thanks for the advise, maybe try and catch is a great way but I am still confused and have never known it before, so the above code is enough for now

wardaddy left a reply on Add Status When Entering Data To Database • 4 months ago

@petrit Your code is the same as the code below, right? I have it but I put it in a modal, so if the user has an input error he should open the modal first to know whether there is a mistake or not, therefore I want to bring up the Materialize Toast to display the error instead of the specific error such as error generated by validator but only displays "not successfully created" so that the user is not confused when the data he input does not enter the database but the error does not appear on the screen even though it has actually been displayed on the modal.

<div class="input-field">
    <input type="text" name="name" value="{{ old('name') }}" required>
    <label>Name</label>
    @if ($errors->has('name'))
        <span>{{ $errors->first('name') }}</span>
    @endif
</div>
<div class="input-field">
    <input type="email" name="email" value="{{ old('email') }}" required>
    <label>Email</label>
    @if ($errors->has('email'))
        <span>{{ $errors->first('email') }}</span>
    @endif
</div>
<div class="input-field">
    <input type="text" name="username" value="{{ old('username') }}" required>
    <label>Username</label>
    @if ($errors->has('username'))
        <span>{{ $errors->first('username') }}</span>
    @endif
</div>
<div class="input-field">
    <input type="password" name="password" required>
    <label>Password</label>
    @if ($errors->has('password'))
        <span>{{ $errors->first('password') }}</span>
    @endif
</div>

what I want to ask is, what is the right condition on if?

if ( condition??? ) {
    return back()->with('status', $success);
} else {
    return back()->with('status', $failed);
}

wardaddy started a new conversation Add Status When Entering Data To Database • 4 months ago

I want to create a status when entering data into the database, if the data is successfully created then the status appears successfully created, and if failed appear unsuccessful, I try like this

UserController

public function store(Request $request)
{
        $this->validate(request(), [
            'name' => 'required|string|min:3|max:40',
            'email' => 'required|string|email|max:40|unique:users',
            'username' => 'required|string|min:6|max:20|alpha_dash|unique:users',
            'password' => 'required|string|min:6|max:40',
        ]);

    $created = User::create([
                    'type_id' => request('user_type'),
                    'name' => request('name'),
                    'email' => request('email'),
                    'username' => request('username'),
                    'password' => bcrypt(request('password')),
                            ]);

    $success = 'Successfully Created';
    $failed = 'Not Successfully Created';

    if ($created) {
        return back()->with('status', $success);
    } else {
        return back()->with('status', $failed);
    }
}

Users.blade.php

@if (session('status'))
    <script>
        $(document).ready(function() {
            M.toast({
                html: '{{ session('status') }}',
                displayLength: '10000'
            });
        });
    </script>
@endif

when the data successfully entered into the database, the status appears successfully created as I expected, but if the data is not successfully entered into the database it does not display any status, what should I do?

12th February, 2018

wardaddy left a reply on Get One Data From Each Duplicate Data Row • 4 months ago

@tisuchi it gives another error

$years = ItemIn::groupBy(DB::raw('MONTH(created_at)'))->pluck('created_at');
(2/2) QueryException
SQLSTATE[HY000]: General error: 1 no such function: MONTH (SQL: select "created_at" from "item_ins" group by MONTH(created_at))

wardaddy left a reply on Get One Data From Each Duplicate Data Row • 4 months ago

@tisuchi, @burlresearch

$years = ItemIn::whereMonth('created_at', '12')->distinct('created_at')->pluck('created_at');
[
    {
        "date": "2017-12-11 10:37:52.000000",
        "timezone_type": 3,
        "timezone": "UTC"
    },
    {
        "date": "2017-12-11 10:38:17.000000",
        "timezone_type": 3,
        "timezone": "UTC"
    },
]

i try like this and still get two december, i just want a month for every month how to get it?

11th February, 2018

wardaddy left a reply on Get One Data From Each Duplicate Data Row • 4 months ago

@tisuchi it's the same as mine, I'm thinking like this

$years = ItemIn::where(DB::raw(MONTH('created_at')), 02)->distinct('created_at')->pluck('created_at');

but there is an error there

(1/1) FatalErrorException
Call to undefined function App\Http\Controllers\MONTH()

in ItemInController.php (line 45)

wardaddy started a new conversation Get One Data From Each Duplicate Data Row • 4 months ago

I want to make select options to display the month taken from the created_at column of a table

// item_ins
+----+--------+---------------------+
| id |  item  |     created_at      |
+----+--------+---------------------+
|  1 | item 1 | 2017-12-11 10:37:52 |
|  2 | item 2 | 2017-12-11 10:38:17 |
|  3 | item 3 | 2018-01-12 01:28:43 |
|  4 | item 4 | 2018-01-12 01:30:14 |
|  5 | item 5 | 2018-02-12 01:30:05 |
|  6 | item 6 | 2018-02-12 01:30:42 |
+----+--------+---------------------+

in the table there are each two months december, january and february, and i want to get one from every same month, i try like this

$years = ItemIn::distinct('created_at')->pluck('created_at');

but I still get the same two months for each month because the timing is not the same, as below

and I'm still confused with how to get just a month because in the above way I get also years and days

[
    {
        "date": "2017-12-11 10:37:52.000000",
        "timezone_type": 3,
        "timezone": "UTC"
    },
    {
        "date": "2017-12-11 10:38:17.000000",
        "timezone_type": 3,
        "timezone": "UTC"
    },
    {
        "date": "2018-01-12 01:28:43.000000",
        "timezone_type": 3,
        "timezone": "UTC"
    },
    {
        "date": "2018-01-12 01:29:14.000000",
        "timezone_type": 3,
        "timezone": "UTC"
    },
    {
        "date": "2018-02-12 01:30:05.000000",
        "timezone_type": 3,
        "timezone": "UTC"
    },
    {
        "date": "2018-02-12 01:30:22.000000",
        "timezone_type": 3,
        "timezone": "UTC"
    },
]

wardaddy left a reply on Laravel 5.4 - Failed To Group Data Based On User Request • 4 months ago

@lostdreamer_nl ok i also think it's a good solution, thanks for your reply

wardaddy started a new conversation Laravel 5.4 - Failed To Group Data Based On User Request • 4 months ago

I want to create a report whose data can be grouped and ordered based on user requests

I have three tables

// items
+----+------------+-------------+-------------+
| id |    name    | category_id | location_id |
+----+------------+-------------+-------------+
|  9 | Mouse 3    | Mouse       | Room 3      |
|  8 | Keyboard 3 | Keyboard    | Room 3      |
|  7 | Monitor 3  | Monitor     | Room 3      |
|  6 | Mouse 2    | Mouse       | Room 2      |
|  5 | Keyboard 2 | Keyboard    | Room 2      |
|  4 | Monitor 2  | Monitor     | Room 2      |
|  3 | Mouse 1    | Mouse       | Room 1      |
|  2 | Keyboard 1 | Keyboard    | Room 1      |
|  1 | Monitor 1  | Monitor     | Room 1      |
+----+------------+-------------+-------------+

// item_categories
+----+----------+
| id |   name   |
+----+----------+
|  3 | Mouse    |
|  2 | Keyboard |
|  1 | Monitor  |
+----+----------+

// item_locations
+----+--------+
| id |  name  |
+----+--------+
|  3 | Room 3 |
|  2 | Room 2 |
|  1 | Room 1 |
+----+--------+

items.blade.php

<div class="input-field">
    <select name="groupBy">
        <option value="not grouped">Not Grouped - Default</option>
        @foreach ($categories as $category)
            <option value="category_id {{ $category->id }}">Category: {{ $category->name }}</option>
        @endforeach
        @foreach ($locations as $location)
            <option value="location_id {{ $location->id }}">Location: {{ $location->name }}</option>
        @endforeach
    </select>
    <label>Group by</label>
</div>
<div class="input-field">
    <select name="orderBy">
        <option value="id asc">Id (Asc) - Default</option>
        <option value="id desc">Id (Desc)</option>
        <option value="name asc">Name (A - Z)</option>
         <option value="name desc">Name (Z - A)</option>
        <option value="updated_at desc">Date (Newest)</option>
        <option value="updated_at asc">Date (Oldest)</option>
    </select>
    <label>Order by</label>
</div>

ReportController

public function items(Request $request)
  {
    $date = Carbon::now()->toFormattedDateString();
    
    $orderByArray = explode(' ', request('orderBy'));
    $orderColumn = $orderByArray[0];
    $orderDirection = $orderByArray[1];

    $groupByArray = explode(' ', request('groupBy'));
    $groupColumn = $groupByArray[0];
    $groupDirection = $groupByArray[1];

    if (request('groupBy') == 'not grouped') {
      $items = Item::Join('item_categories', 'items.category_id', '=', 'item_categories.id')
                   ->Join('item_locations', 'items.location_id', '=', 'item_locations.id')
                   ->select('items.*', 'item_categories.name as category_name', 'item_locations.name as location_name')
                   ->orderBy($orderColumn, $orderDirection)
                   ->get();
    } else {
      $items = Item::Join('item_categories', 'items.category_id', '=', 'item_categories.id')
                   ->Join('item_locations', 'items.location_id', '=', 'item_locations.id')
                   ->select('items.*', 'item_categories.name as category_name', 'item_locations.name as location_name')
                   ->orderBy($orderColumn, $orderDirection)
                   ->groupBy($groupColumn)
                   ->having($groupColumn, '=', $groupDirection)
                   ->get();
    }

    //$pdf = PDF::loadView('report.items', compact('items', 'date'));

    //return $pdf->setPaper('a4')->stream('items.pdf');
    
    return $items;
  }

I try to group by not grouped and ordered by all options and it works well, all data ordered by user request

but when I try to group by category: monitor and order by id (asc) and id (desc) appear only last data entered by user with category id = 1 which is id for monitor category as I showed below

[
    {
        "id": 7,
        "category_id": "1",
        "location_id": "3",
        "name": "Monitor 3",
        "quantity": "0",
        "created_at": "2018-02-11 06:40:08",
        "updated_at": "2018-02-11 06:40:08",
        "category_name": "Monitor",
        "location_name": "Room 3"
    }
]

it also happens if I group by other options and order by other options as well, what should I do?

8th February, 2018

wardaddy started a new conversation Laravel 5.4 - Order Data Based On User Request • 4 months ago

I want to create a report from a table whose data can be ordered based on request from the user, I try as below

suppliers.blade.php

<form id="print" method="POST" action="/admin/suppliers/report" target="blank">
    {{ csrf_field() }}
    <div class="input-field">
        <select name="orderBy">
            <option value="" disabled selected>Order by</option>
            <option value="'id', 'asc'">Id (Asc)</option>
            <option value="'id', 'desc'">Id (Desc)</option>
            <option value="'name', 'asc'">Name (A - Z)</option>
            <option value="'name', 'desc'">Name (Z - A)</option>
            <option value="'updated_at', 'asc'">Date (Asc)</option>
            <option value="'updated_at', 'desc'">Date (Desc)</option>
        </select>
        <label>Order by</label>
     </div>
    <button type="submit" class="btn-flat">print</button>
</form>

Route

Route::post('/admin/suppliers/report', '[email protected]');

ReportController.php

public function supplier(Request $request)
  {
    $orderBy = request('orderBy');

    $suppliers = Supplier::orderBy($orderBy)->get();

    $pdf = PDF::loadView('report.suppliers', compact('suppliers'));

    return $suppliers;
    // return $pdf->setPaper('a4')->stream('suppliers.pdf');
  }

I try to order by Id (Desc) and by Name (Z - A), but the result is always ordered by Id (Asc), as below

[
    {
        "id": 1,
        "name": "Supplier 1",
        "phone": "1111111111",
        "address": "Jl. 1",
        "created_at": "2018-01-27 11:21:35",
        "updated_at": "2018-01-27 11:21:35"
    },
    {
        "id": 2,
        "name": "Supplier 2",
        "phone": "2222222222",
        "address": "Jl. 2",
        "created_at": "2018-01-27 11:21:56",
        "updated_at": "2018-01-27 11:21:56"
    },
    {
        "id": 3,
        "name": "Supplier 3",
        "phone": "3333333333",
        "address": "Jl. 3",
        "created_at": "2018-01-27 11:22:24",
        "updated_at": "2018-01-27 11:22:24"
    }
]

5th February, 2018

wardaddy started a new conversation Laravel 5.4 - How To Prevent One's Role From Being Able To Access The Property Of Another Role ? • 4 months ago

I have an inventory app that has three different roles, namely operator, admin, and super admin.

the problem is when I enter with one of the roles, I can access the menu belongs to another role by writing the link from the menu in the browser's link bar.

example

in the admin page there is a backup and restore menu, link: /admin/backupAndRestore

then I log in as an operator

in the operator page there is only the item borrowing and return item menu, but if I write a link of the admin backup and restore menu in the browser's link bar like localhost: 8000/admin/backupAndRestore I can access the page.

I want to make it like a user who has logged in can not access the register or login page and redirected to the home page, what should I do?

31st January, 2018

wardaddy left a reply on Laravel 5.4 - How To Put File In The Database Directory • 4 months ago

I have solved my problem with the code below, hopefully can help others

    public function restore(Request $request)
    {
        $file = $request->file('database');
        Storage::disk('base')->putFileAs('database', $file, 'database.sqlite');
        
        return back();
    }

29th January, 2018

wardaddy left a reply on Laravel 5.4 - How To Put File In The Database Directory • 4 months ago

@jryd but before I can put the file there

28th January, 2018

wardaddy left a reply on Laravel 5.4 - How To Put File In The Database Directory • 4 months ago

@jryd I have tried your suggestion and got error like picture below

image

wardaddy started a new conversation Laravel 5.4 - How To Put File In The Database Directory • 4 months ago

I'm working on the database restore menu for an application I created, I'm using sqlite for my database, and I want to put my previously backed up database file to the database directory

backupAndRestore.blade.php

<form method="POST" action="/admin/backupAndRestore/restore" enctype="multipart/form-data">
                {{ csrf_field() }}
                <div class="file-field input-field">
                  <div class="btn">
                    <span><i class="material-icons">file_upload</i></span>
                    <input type="file" name="database" accept=".sqlite">
                  </div>
                  <div class="file-path-wrapper">
                    <input type="text" class="file-path" placeholder="Example: file_name.sqlite" readonly>
                  </div>
                </div>
                <button type="submit" class="btn">restore</button>
              </form>

Route

Route::post('/admin/backupAndRestore/restore', '[email protected]');

DatabaseController.php

public function restore(Request $request)
    {
        $database = $request->database;
        $file_name = 'database2.sqlite';
        $path = database_path($file_name);

        file_put_contents($path, $database);

        return $path;
    }

my code works, the file is stored in the database directory, the problem is when I backup my database file size is 22kb, but when I restore it and I check the database directory, the file is 1kb size and when I open using sublime file contents as shown below

Images

which I expect as shown below

Images

24th January, 2018

wardaddy left a reply on Laravel 5.4 - Class Not Found In Controller • 4 months ago

@Snapey Thanks for helping me

23rd January, 2018

wardaddy left a reply on Laravel 5.4 - Class Not Found In Controller • 4 months ago

@Cronix of course, this is my folder structure

https://i.imgur.com/koHeCdM.png

wardaddy left a reply on Laravel 5.4 - Class Not Found In Controller • 4 months ago

@Snapey

the error like this

https://i.imgur.com/u5UlLIAg.png

and this is my folder struchture

https://i.imgur.com/koHeCdM.png

wardaddy left a reply on Laravel 5.4 - Class Not Found In Controller • 4 months ago

@Talinon yes, i have it

wardaddy left a reply on Laravel 5.4 - Class Not Found In Controller • 4 months ago

@Snapey

<?php

namespace App\Http\Controllers;

use App\ItemCategories;
use App\ItemLocation;
use App\Item;
use Illuminate\Http\Request;

class ItemController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        $items = Item::Join('item_categories', 'items.category_id', '=', 'item_categories.id')
                     ->Join('item_locations', 'items.location_id', '=', 'item_locations.id')
                     ->select('items.*', 'item_categories.name as category_name', 'item_locations.name as location_name')
                     ->orderBy('updated_at', 'desc')
                     ->get();

        $categories = ItemCategories::orderBy('id')->get();

        $locations = ItemLocations::orderBy('id')->get();

        return view('auth.admin.items', compact('items'));
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $this->validate(request(), [
            'name' => 'required|string|max:50'
        ]);

        Item::create(request(['name', 'category_id']));

        return back();
    }

    /**
     * Display the specified resource.
     *
     * @param  \App\Item  $item
     * @return \Illuminate\Http\Response
     */
    public function show(Item $item)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\Item  $item
     * @return \Illuminate\Http\Response
     */
    public function edit(Item $item)
    {
        $items = Item::Join('item_categories', 'items.category_id', '=', 'item_categories.id')
                     ->select('items.*', 'item_categories.name as category_name')
                     ->where('items.id', '=', $item->id)
                     ->get();

        return view('auth.admin.editItem', compact('items'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Item  $item
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, Item $item)
    {
        $item = Item::find($item->id);

        $this->validate(request(), [
            'name' => 'required|string|max:50'
        ]);

        $item->name = $request->name;
        $item->save();

        return back();
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\Item  $item
     * @return \Illuminate\Http\Response
     */
    public function destroy(Item $item)
    {
        Item::find($item->id)->delete();

        return back();
    }
}

wardaddy left a reply on Laravel 5.4 - Class Not Found In Controller • 4 months ago

My model is stored in the app folder

i have tried like this

use ItemCategories;
use ItemLocation;

like this

use App\ItemCategories;
use App\ItemLocation;

and like this

use \App\ItemCategories;
use \App\ItemLocation;

and the result remains the same, just this time I experienced it, in my previous project I just write like 'Use User' and 'Use Channel' and it works well, I think it's like a bug or something like that, I have tried 'composer dump-autoload 'and nothing happens, can someone help me?

wardaddy started a new conversation Laravel 5.4 - Class Not Found In Controller • 4 months ago

I have three models, namely Item, ItemCategories, and ItemLocation and on ItemController.php I want to include ItemCategories and ItemLocation but I get an error as below, what should I do?

(1/1) FatalErrorException
Class 'ItemCategories' not found

ItemController.php

use ItemCategories; <-- I have included this at the top
use ItemLocation;  <-- I have included this at the top


public function create()
    {
        $items = Item::Join('item_categories', 'items.category_id', '=', 'item_categories.id')
                     ->Join('item_locations', 'items.location_id', '=', 'item_locations.id')
                     ->select('items.*', 'item_categories.name as category_name', 'item_locations.name as location_name')
                     ->orderBy('updated_at', 'desc')
                     ->get();

        $categories = ItemCategories::orderBy('id')->get();

        $locations = ItemLocation::orderBy('id')->get();

        return view('auth.admin.items', compact('items', 'categories', 'locations'));
    }

21st December, 2017

wardaddy left a reply on Fails To Redirect Multiple Authentication To Different Pages • 5 months ago

@bobbybouwmann i have tried suggestions from here

redirecting three different user types/roles to different pages

and as I explained above, I still have a problem

I tried to sign in using a user with type_id = 1, which means the user is a super admin, but it always redirects to Route::get('/','[email protected]'); as well as users with other roles

and the problem is that each role can access the page belongs to another role, what should I do to fix it?

20th December, 2017

wardaddy left a reply on Redirecting Users And Admins To Different Pages • 5 months ago

@bobbybouwmann I follow your way like this

use Auth;

//protected $redirectTo = '/home';
public function redirectTo()
{
    $superAdmin = Auth::user()->type_id = 1;
        $admin = Auth::user()->type_id = 2;
        $cashier = Auth::user()->type_id = 3;

        if ($superAdmin) {
        return '/superAdmin/home';
        }
        elseif ($admin) {
        return '/admin/home';
        }
        elseif ($cashier) {
        return '/cashier/home';
        }
}

but it always redirects to '/superAdmin/home'

17th December, 2017

wardaddy left a reply on Redirecting Users And Admins To Different Pages • 6 months ago

@bobbybouwmann what about protected $ redirectTo = '/ home';

do i have to delete it or just ignore it?

wardaddy left a reply on Redirecting Users And Admins To Different Pages • 6 months ago

I mean when login authentication I want admin to be redirected to "admin page" and user is redirected to "user page"

wardaddy started a new conversation Redirecting Users And Admins To Different Pages • 6 months ago

I use laravel 5.4 and I have two tables

types table id | 1 , 2 name | admin , user

users table id | 1 , 2 type_id | 1 , 2 name | john , jane

I want to redirect admin and user to different page, user to "user page" and admin to "admin page", what should I do?

wardaddy left a reply on Sqlite Table Relation On The Database Migration • 6 months ago

@burlresearch i want to do like this

CREATE TABLE users (
 id integer PRIMARY KEY,
username varchar NOT NULL,
password varchar NOT NULL
 type_id integer NOT NULL,
    FOREIGN KEY (type_id) REFERENCES types(id)
);

wardaddy started a new conversation Add Sqlite Table Relation On The Database Migration • 6 months ago

I have two tables

I am using laravel 5.4 and I want to fill the type_id in user table with data on id in types table, if possible i want to do it on database migration

I have two tables

Types table

id

name

Users table

id

type_id

username

password

12th October, 2017

wardaddy started a new conversation Failed To Move Files To Public Directory • 8 months ago

I want to move the song into the channel folder in the public directory

but when I run the code, it shows the word "No file selected", can someone help solve my problem?

here my code

MusicController.php

public function store(Request $request)
    {
        if ($request->hasFile('music')) {
            $request->file('music');

            return Storage::putFile('public/'.$channel->name, $request->file('music'));
        } else {
            return 'No file selected';
        }
    }

route/web.php

Route::post('/musics/store', '[email protected]');

show.blade.php

<form  method="POST" action="/musics/store" id="add-video">
    <div>
        <div class="file-field input-field mt-5">
            {{ csrf_field() }}
            <div class="btn">
                <span>Browse</span>
                <input type="file" name="music" accept="audio/mpeg3" required>
            </div>
            <div class="file-path-wrapper">
                <input class="file-path validate" type="text">
            </div>
        </div>
    </div>
    <div>
        <button type="submit" class="btn-flat">submit</button>
    </div>
</form>

wardaddy started a new conversation Insert The "name" Data Into The Database And Create A Directory With The Same Name At The Same Time • 8 months ago

I want to insert "channel name" into the channel table and create a storage with the same name in the storage /app /public folder

example: if I enter "Channel # 1" in the input field and click on submit button, it will insert the data into the channel table and simultaneously create the storage with the name "Channel # 1" in folder storage /app/public

here my code

ChannelController.php

public function store(Request $request)
{
    $channel = new Channel;

    Channel::create([
        'name' => request('channel_name')
    ]);
        
    $dirName = request('channel-name');
    $makeDir = Storage::makeDirectory('public/'.$dirName);

    return redirect('/dash/manage-channels');
}

manageChannels.blade.php

<form method="POST" action="/channels/create" class="file-field input-field">
    {{ csrf_field() }}
    <button type="submit" class="btn">submit</button>
    <div>
        <input type="text" name="channel_name" placeholder="Channel Name" id="channel_name" class="validate">
        <label for="channel_name" class="light">Add Channel</label>
    </div>
</form>

but if I click on the "submit" button, it just puts the data into the channels table and does not create storage in storage folder / app / public, how to fix it?

wardaddy started a new conversation How To Enter Data Into A Database While Creating A Storage With The Same Name ? • 8 months ago

I want to insert "channel name" into the channel table and create a storage with the same name in the storage /app /public folder

example: if I enter "Channel # 1" in the input field and click on submit button, it will insert the data into the channel table and simultaneously create the storage with the name "Channel # 1" in folder storage /app/public

here my code

ChannelController.php

public function store(Request $request)
{
    $channel = new Channel;

    Channel::create([
        'name' => request('channel_name')
    ]);
        
    $dirName = request('channel-name');
    $makeDir = Storage::makeDirectory('public/'.$dirName);

    return redirect('/dash/manage-channels');
}

manageChannels.blade.php

<form method="POST" action="/channels/create" class="file-field input-field">
    {{ csrf_field() }}
    <button type="submit" class="btn">submit</button>
    <div>
        <input type="text" name="channel_name" placeholder="Channel Name" id="channel_name" class="validate">
        <label for="channel_name" class="light">Add Channel</label>
    </div>
</form>

but if I click on the "submit" button, it just puts the data into the channels table and does not create storage in storage folder / app / public, how to fix it?

10th October, 2017

wardaddy left a reply on Failed To Display Data With `whereNotNull` Method • 8 months ago

aah I always forget with it, thanks @Corban

wardaddy started a new conversation Failed To Display Data With `whereNotNull` Method • 8 months ago

I want to show the channel data where "user_id" != "NULL"

I use whereNotNull method for it but it does not show anything on the view, is there something wrong with my code?

here my code

channelController.php

public function index()
{
    $channels = Channel::whereNotNull('user_id');

    return view('channels.master', compact('channels'));
}

master.blade.php

@foreach ($channels as $channel)
    <div class="col s12 m4 center">
            <a href="/channels/{{ $channel->id }}">
                <img src="assets/img/avatar-default.png">
                <h3>{{ $channel->name }}</h3>
                <p>Dj Name</p>
        </a>
    </div>
@endforeach

wardaddy left a reply on How To Delete Data And Update Data From Two Different Tables At The Same Time ? • 8 months ago

@tisuchi what is the purpose of $ channelid

I have tried your code, I tried to delete user and DJ but there is still error there

public function destroy($channelid, $id)
{
    $hasUser = User::find($id);
    if($hasUser){
        $hasUser->delete();
    }

        $channel = Channel::find($channelid);
        if($channel) {
        $channel->user_id = NULL;
        $channel->save();
    }

    return redirect('/dash/manage-users');
}

it says

(1/1) ErrorException

Missing argument 2 for App\Http\Controllers\UserController::destroy()

wardaddy left a reply on How To Delete Data And Update Data From Two Different Tables At The Same Time ? • 8 months ago

there are errors there

when I try to delete the user it says

FatalErrorException Call to a member function delete () on null

and when I tried removing the DJ it said

(1/2) PDOException SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (discjoke.channels, CONSTRAINT channels_ibfk_1 FOREIGN KEY (user_id) REFERENCES users (id))

(2/2) QueryException SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (discjoke.channels, CONSTRAINT channels_ibfk_1 FOREIGN KEY (user_id) REFERENCES users (id)) (SQL: delete from users where id = 4)

wardaddy started a new conversation How To Delete Data And Update Data From Two Different Tables At The Same Time ? • 8 months ago

I have a music app with three different user types, namely "user" with type_id = 3, "DJ" with type_id = 2, and "admin" with type_id = 1

pada halaman admin terdapat daftar user dan juga DJ dengan aksi "hapus"

DJ List

  • ID _______| 1 _| 2|

  • NAME____| john | jane|

  • CHANNEL | john channel | jane channel |

  • ACTION | delete____| delete _____|

User List

  • ID _____| 3 ____| 4 ____|

  • NAME__| dave | mike_|

  • ACTION | delete | delete |

this is what i need

if the admin clicks "delete" on the user, I just want to delete all the data itself on the users table

and if the admin clicks on "delete" on the DJ, I want to delete all his data from the users table and also update the user_id whose value is the same as the id of the DJ on the channel table to "NULL"

what can i do to get those things ?

Users Table

  • ID______| 1 | 2| 3___| 4 ___|

  • TYPE_ID | 2___| 2___| 3___| 3 ___|

  • NAME __| john | jane | dave | mike |

Channels Table

  • ID______| 1__________| 2__________| 3_________|

  • USER_ID | 1__________| 2__________| NULL _____|

  • NAME __| john channel | jane channel | Channel #3 |

here my code

UserController.php

public function destroy(channel $channel, $id)
{
    User::find($id)->delete();

    $channel = App\Channel::find($channel->id);
    $channel->user_id = NULL;
    $channel->save();

    return redirect('/dash/manage-users');
}

routes/web.php

Route::delete('/users/{id}/delete', '[email protected]');

manageUsers.blade.php

<h5 class="light">DJ List</h5>
<table>
    <thead>
        <tr>
            <th>id</th>
            <th>name</th>
            <th>channel</th>
            <th>action</th>
        </tr>
    </thead>
    <tbody>
        @foreach ($djs as $dj)
                <tr>
                    <td>{{ $dj->id }}</td>
                    <td>{{ $dj->name }}</td>
                    <td>{{ $dj->channel_name }}</td>
                    <td>
                        <form method="POST" action="/users/{{ $dj->id }}/delete">
                        {{ csrf_field() }}
                            {{ method_field('DELETE') }}
                        <button class="btn-flat">delete</button>
                    </form>
                    </td>
            </tr>
        @endforeach
    </tbody>
</table>

<h5 class="light">User List</h5>
<table>
    <thead>
        <tr>
            <th>id</th>
            <th>name</th>
            <th>action</th>
        </tr>
    </thead>
    <tbody>
        @foreach ($users as $user)
                <tr>
                    <td>{{ $user->id }}</td>
                    <td>{{ $user->name }}</td>
                    <td>
                        <form method="POST" action="/users/{{ $user->id }}/delete">
                        {{ csrf_field() }}
                            {{ method_field('DELETE') }}
                        <button class="btn-flat">delete</button>
                    </form>
                    </td>
            </tr>
        @endforeach
    </tbody>
</table>

wardaddy left a reply on How Best Way To Display The Sequence Number? • 8 months ago

@bobbybouwmann thanks, it's very easy to use because I do not need to write a variable on the controller to get it

9th October, 2017

wardaddy left a reply on How To Get All The Rows Of Data + Joins Data From The Database ? • 8 months ago

wow itu sangat jauh lebih efisien dibandingkan kode milikku, terimakasih @Stratos

wardaddy left a reply on How To Get All The Rows Of Data + Joins Data From The Database ? • 8 months ago

@ftrillo thanks again, you really helped me

get data from related models if you take advantage of Eloquent relationships.

I can't understand what you mean now, the code I have is enough for me now, maybe someday I can learn a more efficient way to do the things I want, but thanks for telling me

wardaddy started a new conversation How To Get All The Rows Of Data + Joins Data From The Database ? • 8 months ago

I want to show all the rows of data from the database plus data from joins function

Channels Table

| id | user_id | name |

|----|----------|--------|

| 1 | 1 | channel #1 |

| 2 | 2 | channel #2 |

| 3 | NULL | channel #2 |

| 4 | NULL | channel #2 |

Users Table

| id | name |

|----|--------|

| 1 | John |

| 2 | Jane |

here my code

dashboardController.php

public function index()
{
    $channels = Channel::join('users', 'channels.user_id', '=', 'users.id')
                     ->select('channels.*', 'users.name as dj_name')
                     ->orderBy('updated_at', 'desc')
                     ->get();

    return view('dashboard.master', compact('channels'));
}

master.blade.php

@foreach ($channels->take(4) as $channel)
    <div class="col s12 m4 l3">
        <div class="card grey lighten-4 z-depth-0">
            <div class="card-content">
                <h5 class="truncate">{{ $channel->name }}</h5>
                <div class="d-flex justify-content-between align-items-end">
                    <div>
                        @if ($channel->user_id == NULL)
                            <p class="lead mt-1">No DJ here!</p>
                        @else
                            <p class="lead mt-1">DJ : {{ $channel->dj_name }}</p>
                        @endif
                        <small>ID Channel : {{ $channel->id }}</small>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endforeach

if I run this code, it only shows channels that have user_id and does not display channels with user_id = "NULL"

what should I do to display a channel that has users_id along with a channel with user_id = "NULL"?

wardaddy left a reply on Is It Possible To Get Title And Thumbnail Image From Youtube Video Using Laravel ? • 8 months ago

thanks for telling me, although it's quite confusing

wish me luck

wardaddy started a new conversation Is It Possible To Get Title And Thumbnail Image From Youtube Video Using Laravel ? • 8 months ago

is it possible to get title and thumbnail image from youtube video using laravelI want to create a web-based app to create a personal playlist of videos taken from youtube

so if I insert a video link from youtube into the input field and click on the "add" button, it automatically gets the title and also the thumbnail image of the added video and inserts it into the database.

whether it can be done using laravel?

can someone tell me how I should do to get those things, or just share a link to do those things as a reference?

wardaddy left a reply on The Best Way To Display The Sequence Number? • 8 months ago

@bobbybouwmann it just like I did before, but I initialize the variable number on the controller with('no', 1)

here

return view('dashboard.manageUsers', compact('users', 'djs'))->with('no', 1);

and here

<td>{{ $no++ }}</td>

wardaddy started a new conversation The Best Way To Display The Sequence Number? • 8 months ago

I want to display the serial number of each row of data on two tables, and I want the number to start from one on each table, like the table below

DJ List | # | id | username | etc | | --- | --- | --- | --- | | 1 | 1 | john | ... | | 2 | 2 | jane | ... |

User List | # | id | username | etc | | --- | --- | --- | --- | | 1 | 3 | dave | ... | | 2 | 4 | dick | ... |

but what I get is like in the table below

DJ List | # | id | username | etc | | --- | --- | --- | --- | | 1 | 1 | john | ... | | 2 | 2 | jane | ... |

User List | # | id | username | etc | | --- | --- | --- | --- | | 3 | 3 | dave | ... | | 4 | 4 | dick | ... |

here my code

manageUsers.blade.php

<div class="col s12">
        <h5 class="light">DJ List</h5>
    <table class="responsive-table bordered centered highlight mb-5">
        <thead>
            <tr>
                <th>#</th>
                <th>ID</th>
                <th>Username</th>
                <th>Email</th>
                <th>Channel</th>
                <th>Changed on</th>
                <th>Action</th>
            </tr>
        </thead>
        <tbody>
            @foreach ($djs as $dj)
                <tr>
                    <td>{{ $no++ }}</td>
                    <td>{{ $dj->id }}</td>
                    <td>{{ $dj->name }}</td>
                    <td>{{ $dj->email }}</td>
                    <td>{{ $dj->channel_name }}</td>
                    <td>{{ $dj->updated_at }}</td>
                    <td>
                        <a href="/users/{{ $dj->id }}/delete">delete</a>
                    </td>
                </tr>
            @endforeach
        </tbody>
    </table>
    <h5 class="light">User List</h5>
    <table class="responsive-table bordered centered highlight mb-3">
        <thead>
            <tr>
                <th>#</th>
                <th>ID</th>
                <th>Username</th>
                <th>Email</th>
                <th>Joined on</th>
                <th>Action</th>
            </tr>
        </thead>
        <tbody>
            @foreach ($users as $user)
                <tr>
                    <td>{{ $no++ }}</td>
                    <td>{{ $user->id }}</td>
                    <td>{{ $user->name }}</td>
                    <td>{{ $user->email }}</td>
                    <td>{{ $user->created_at }}</td>
                    <td>
                        <a href="/user/{{ $user->id }}/delete">delete</a>
                    </td>
                </tr>
            @endforeach
        </tbody>
    </table>
</div>

UserController.php

public function index()
{
    $djs = User::join('channels', 'users.id', '=', 'channels.user_id')
                    ->select('users.*', 'channels.name as channel_name')
                    ->where('type_id', '=', '2')
                    ->orderBy('updated_at', 'desc')
                    ->get();
    $users = User::where('type_id', '=', '3')->orderBy('created_at', 'desc')->get();

    return view('dashboard.manageUsers', compact('users', 'djs'))->with('no', 1);
}

can someone tell where my fault is, or help to tell a better way than this?

wardaddy left a reply on How To Get Id From Auth::user() ? • 8 months ago

@zachleigh thanks a lot, your code works well and is easy to understand

wardaddy left a reply on How To Get Id From Auth::user() ? • 8 months ago

I have tried your suggestion and there it appears FatalErrorException

Call to a member function channels() on null

8th October, 2017

wardaddy left a reply on How To Get Id From Auth::user() ? • 8 months ago

the code leads me to 'dashboard.channel', but does not display the information from the channel as I expected

here my code in manageChannel.blade.php

@foreach ($channels as $channel)
        <form method="POST" action="/channels/{id}/edit" class="file-field input-field">
        {{ csrf_field() }}
        {{ method_field('PUT') }}
        <button type="submit" class="btn light-blue waves-effect waves-light right px-3">submit</button>
        <div class="file-path-wrapper pl-0 pr-3">
            <input type="text" name="channel_name" id="channel_name" value="{{ $channel->name }}" class="validate">
            <label for="channel_name" class="light">Rename Channel</label>
        </div>
    </form>
@endforeach

wardaddy started a new conversation How To Get Id From Auth::user() ? • 8 months ago

I want to display the data from the channel where "user_id" in the channel table is the same as the "id" of Auth :: user ()

Users Table id | name | email | password --- | --- | --- | --- 1 | john | [email protected] | 123 2 | jane | [email protected] | 321

Channels Table id | user_id | name --- | --- | --- 1 | 1 | Channel #1 2 | 2 | Channel #2

this is what i need

if user selects "Manage Channel" menu, the menu will display information from his own channel

dashboard.blade.php

<a href="{{ url('/dash/manage-channel') }}" class="waves-effect"><i class="material-icons left">view_list</i>Manage Channel</a>

here my code channelController.php

use Auth; //has been added at the top


public function edit(channel $channel)
{
     $channels = Channel::where('user_id', '=', Auth::user()->id); //trying to get id from Auth::user()
     return view('dashboard.manageChannel', compact('channels'));
}
Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.