wardaddy

Experience

930

0 Best Reply Awards

  • Member Since 2 Weeks Ago
  • 0 Lessons Completed
  • 0 Favorites

12th October, 2017

wardaddy started a new conversation Failed To Move Files To Public Directory • 6 days 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 • 6 days 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 ? • 6 days 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 • 1 week ago

aah I always forget with it, thanks @Corban

wardaddy started a new conversation Failed To Display Data With `whereNotNull` Method • 1 week 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 ? • 1 week 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 ? • 1 week 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 ? • 1 week 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? • 1 week 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 ? • 1 week 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 ? • 1 week 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 ? • 1 week 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 ? • 1 week 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 ? • 1 week 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? • 1 week 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? • 1 week 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() ? • 1 week 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() ? • 1 week 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() ? • 1 week 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() ? • 1 week 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'));
}

wardaddy left a reply on How To Update Two Data In Two Different Tables ? • 1 week ago

@ftrillo this works like a charm, thanks a lot for helping me

7th October, 2017

wardaddy left a reply on How To Update Two Data In Two Different Tables ? • 1 week ago

@ftrillo can you tell me what I can do?

this is what I am trying to do

if the user clicks on the "take channel" button,

<a href="/become-dj/{{ $channel->id }}/process" class="btn-flat"><i class="material-icons">flag</i></a>

I want to update the type_id in the users table from "3" to "2", which means the user has changed to a dj,

$channel = App\Channel::find(id);  //trying to retrieve the id from the channel selected by the user

$channel->user_id = Auth::user()->id; //updating the user_id on the channel table with the id of the user who clicked on the button
$channel->save(); //
and save it to the database

and also fill user_id in the channel table with the id of the user who clicked the button

$user = App\User::find('type_id'); //trying to retrieve the id from the user who clicked the button
$user->type_id = '2'; //change the id from "3" to "2", which means the user has changed to a dj
$user->save(); //
and save it to the database

wardaddy started a new conversation How To Update Two Data In Different Tables ? • 1 week ago

I have two tables and I want to update two data on different tables at a time

users table

  • id --> "1"
  • type_id --> "3"
  • name --> "john"
  • email --> "[email protected]"
  • password --> "123"

channels table

  • id --> "1"
  • user_id --> "null"
  • name --> "channel #1"

*type_id --> 1 = admin, 2 = dj, 3 = user

here my code

becomeDJ.blade.php

@foreach ($channels as $channel)
    <div class="col s12 m4 l3">
        <div class="card grey lighten-4">
            <div class="card-content p-3">
                <h5 class="truncate mt-0 mb-0">{{ $channel->name }}</h5>
                <div class="d-flex justify-content-between">
                    <div>
                        <p>DJ : Username</p>
                        <small>ID Channel : {{ $channel->id }}</small>
                    </div>
                    <a href="/become-dj/{{ $channel->id }}/process" class="btn-flat"><i class="material-icons">flag</i></a>
                </div>
            </div>
        </div>
    </div>
@endforeach

routes/web.php

Route::get('/become-dj/{channel}/process', '[email protected]');

UserController.php

public function becomeDJ()
{
    $channel = App\Channel::find('id');
    $channel->user_id = Auth::user()->id;
    $channel->save();

    $user = App\User::find('type_id');
    $user->type_id = '2';
    $user->save();

    return view('dashboard.editChannel');
}

29th September, 2017

wardaddy started a new conversation How To Add Where Condition On Link? • 2 weeks ago

I want to display the link "/ channel / {{channel_id}}" where the channel id has been determined based on the id of the user from the channel table.

channels table

  • channel_id
  • channel_name
  • user_id // index of user_id in the user table

users -user_id -user_name

if the user enters and hits the link, it will go directly to the specified page

I have tried using the code cisit channell `

28th September, 2017

wardaddy left a reply on Failed To Get The File To Display On Iframe, What Should I Do? • 2 weeks ago

thanks for the clue, my problem is solved now sorry for spamming others

wardaddy left a reply on Fails To Display Data On Iframe On Laravel 5.4, What Should I Do? • 2 weeks ago

thanks for the clue, my problem is solved now

sorry for spamming others

wardaddy started a new conversation Failed To Get The File To Display On Iframe, What Should I Do? • 2 weeks ago

i am using laravel 5.4 and i want to display the file in /dashboard/dashboard.blade.php folder on iframe

folder structure:

  • /dashboard/dashboard.blade.php

  • layout.blade.php

  • index.blade.php

this is my code inside layout.blade.php

<iframe src="dashboard/dashboard.blade.php"> </ iframe>

I tried displaying index.blade.php on an iframe using the src ="index.blade.php" method and it worked, but I can not display dashboard.blade.php in the same way, it says the file was not found.

wardaddy started a new conversation Failed To Get File To Display On Iframe, What Should I Do? • 2 weeks ago

i am using laravel 5.4 and i want to display the file in /dashboard/dashboard.blade.php folder on iframe

folder structure:

  • /dashboard/dashboard.blade.php

  • layout.blade.php

  • index.blade.php

this is my code inside layout.blade.php

<iframe src =" dashboard / dashboard.blade.php "> </ iframe>

I tried displaying index.blade.php on an iframe using the src =" index.blade.php " method and it worked, but I can not display dashboard.blade.php in the same way, it says the file was not found.

wardaddy left a reply on Fails To Display Data On Iframe On Laravel 5.4, What Should I Do? • 2 weeks ago

@topvillas what's the code? sorry i newbie in laravel

wardaddy started a new conversation Display Files On Iframe • 2 weeks ago

i am using laravel 5.4 and i want to display the file in /dashboard/dashboard.blade.php folder on iframe

folder structure: layout.blade.php /dashboard/dashboard.blade.php

this is my code inside layout.blade.php

wardaddy started a new conversation How To Add Where Condition On Laravel Blade? • 2 weeks ago

here my code @if (Auth::user()->where('type_id', 1)) //Admin showing Add Channel @elseif (Auth::user()->where('type_id', 2)) //DJ showing My Channel @elseif (Auth::user()->where('type_id', 1)) //User display nothing @else //Guest display nothing

What should I do?

Edit Your Profile
Update

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