ziben69

ziben69

Member Since 6 Months Ago

Experience Points 2,130
Experience
Level
Lessons Completed 0
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

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

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

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

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

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

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

21 Jan
1 day ago

ziben69 left a reply on Photo Validation In Relationship

@TISUCHI - Thanks, that's it <3

ziben69 left a reply on Photo Validation In Relationship

@TISUCHI - Trying to get property 'filename' of non-object

still the same

ziben69 started a new conversation Photo Validation In Relationship

Hello guys,

I have two models in relationship - one to many:

Model: Business and Model Photo. Everything works nicely, only when I try to display using the method only the first photo for a given business pops up an error.

My function:

public function singlePhotoForSingleEvent() {
        return $this->photos()->first();
    }

How can I validate this function, because if I don't have a photo in the database, it throw an error.

The above function is in the Business model, not in the controller.

I should write something like:

if($request->has('photos')) or something?

Thanks for help!

12 Jan
1 week ago

ziben69 left a reply on Two Post Forms In | Route Problem

Hah, o my... im idiot :D Thanks...

ziben69 started a new conversation Two Post Forms In | Route Problem

Hello guys, in the main view I have two links pointing to two different creation views with the forms.

Link one:

<a href="{{ URL::to('business/media') }}"
                               class="btn btn-md btn-dark">Create</a>

Link two:

<a href="{{ URL::to('business/create') }}"
                               class="btn btn-md btn-primary">Create</a>

and routes to first button:

Route::get('business/media','[email protected]')->middleware('auth');
Route::post('business/', '[email protected]')->middleware('auth');

to second button:

Route::get('business/create','[email protected]')->middleware('auth');
Route::post('business/', '[email protected]')->middleware('auth');

these two buttons are included in one business view.

after clicking the button A everything is OK, after clicking the B button I get an error and the routing is directed to the path of the button A.

What can I do to make both buttons work?

ziben69 left a reply on Video Upload | One To Many Relationship

Exception: Too few arguments to function App\Http\Controllers\BusinessController::addVideo(), 1 passed and exactly 2 expected

ziben69 left a reply on Video Upload | One To Many Relationship

I use foreach loops because it is multiupload.

I do not understand how I can save your video way.

I have two tables: Business and Video There is a one to many relationship between them.

So one business can have many videos.

And now I just want to get something like this after adding a movie or movies to the database:

For example video record: id = 1; business_id = 4; title = 'test';

id = 2; business_id = 4; title = 'test2'; ... etc

ziben69 started a new conversation Video Upload | One To Many Relationship

Hello guys,

I did upload video files, but I have some problem in the controller with the file saved.

Relation on models: Video:

 protected $fillable = [
        'filename',
        'title',
        'layout',
        'description',
        'business_id',
    ];
     public $timestamps = false;

  public function business()
    {
        return $this->belongsTo(Business::class, 'business_id');
    }

Business:

    public function videos()
    {
        return $this->hasMany(Video::class);   
    }

foreign key:

public function up()
    {
Schema::table('videos', function(Blueprint $table){
 $table->integer('business_id')->unsigned()->change();
 $table->foreign('business_id','videos_business_id_foreign')->references('id')->on('businesses');
});
    }

BusinessController (addVideo):

  public function addVideo(Request $request)
    {
        foreach ($request->videos as $video) {
            $filename = $video->store('videos');
            Video::create([
                'business_id' => $business->id,
                'filename' => $filename,
                'title' => $title,
                'description' => $description,
                'layout' => $layout
            ]);
        }
        return redirect()->action('[email protected]');
    }

Function addVideo creates a record in the Business table, but the problem appears at:

foreach ($request->videos as $video) {

Error:

"Invalid argument supplied for foreach()"

Part of routes web.php:

Route::get('business/media','[email protected]')->middleware('auth');

Route::post('business/', '[email protected]')->middleware('auth');

Fragment of form post:

 <form action="{{ action ('[email protected]')}}" method="POST"
                          enctype="multipart/form-data">
.
.
.
<div class="form-group">
    <input type="file" id="upload" onchange="ValidateSize(this)" name="file" multiple aria-describedby="fileHelp"/>
</div>
<input type="submit" value="Create" class="btn btn-primary"/>
</form>

I dont know why it doesn't work. Can anyone help me? Thanks

04 Jan
2 weeks ago

ziben69 left a reply on How To Decode Json Array

I just removed ->last(); from Sport::all()->last(); and it worked. Solved, to close.

Thanks

ziben69 left a reply on How To Decode Json Array

Could anyone help, please

03 Jan
2 weeks ago

ziben69 left a reply on How To Decode Json Array

@THEMORGZ - I added json_decode in AppServicePrivoder:

            $listOfDatabasesData = json_decode($results, true);
            
            $view->with('sidebar', $listOfDatabasesData); 

Result:

json_decode() expects parameter 1 to be string, array given

ziben69 started a new conversation How To Decode Json Array

Hello guys,

I need to display titles from database in sidebar, and I did something like this: AppServiceProvider.php

   view()->composer('*', function($view){

            $results = [];
            $results['zone'] = Zone::all()->last();
            $results['tourism'] = Tourism::all()->last();
            $results['business'] = Business::all()->last();
            $results['culture'] = Culture::all()->last();
            $results['education'] = Education::all()->last();
            $results['inhabitant'] = Inhabitant::all()->last();
            $results['investor'] = Investor::all()->last();
            $results['senior'] = Senior::all()->last();
            $results['sport'] = Sport::all()->last();

            $view->with('sidebar', $results); 
        });

it's almost okay, I get a result in the form of a json array that looks like this:

{"id":1,"title":"test","description":"<p>test<\/p>","path":"dsadsa","created_at":"2019-01-03 10:25:33","updated_at":"2019-01-03 10:25:33"} {"id":2,"title":"rtest2","description":"<p>dssads<\/p>","path":"dsadas","created_at":"2019-01-03 10:33:58","updated_at":"2019-01-03 10:33:58"}...

because I have a json result, I can not only display the title. Below fragment of the view:

    @foreach($sidebar as $type => $list)
           {{ $list }}
    @endforeach

I need do something like this:

    @foreach($sidebar as $type => $list)
    @foreach($list as $item)
           {{ $item->title }}
    @endforeach
    @endforeach

but I have exception:

Invalid argument supplied for foreach().

Thanks for help.

25 Dec
4 weeks ago

ziben69 left a reply on Laravel | Problem With The Conditional Loop In The Search Engine

I want to, after entering, for example: test, the results containing the word test appear in the title. If it does not exist in all these models, it should be unsubscribed once: No data. If "test" appears at least once, then there should be one result, not 9x No data and 1x "test". Just like normal search engines.

ziben69 left a reply on Laravel | Problem With The Conditional Loop In The Search Engine

but now it works on the principle: If there is no data in the given partial view, write No data. And he writes me 10x, and even if there is data in a calendar table for example, he writes me 9x No data and once the result is good

ziben69 left a reply on Laravel | Problem With The Conditional Loop In The Search Engine

So now in partial views I have:

<div class="row">
    @foreach($items as $item)
    <div class="col-md-4" style="margin-bottom:10px;">
        <div class="card search-card">
            <div class="card-body">
                <strong class="card-title">
                    {{ $item->title}}
                </strong>
                {!! $item->description !!}
            </div>
        </div>
    </div>
    @endforeach
</div>

in search.blade.php I have:

   <div class="row">
            <div class="col-12 col-lg-4">
                <!-- Single Contact Information -->
                @foreach($results as $type => $list)
                @if (!empty($list))
                <div class="single-contact-information mb-30">
                    @include('pages.search-results.'. $type, ['items' => $list])
                </div>
                @else
                <hr/>
                <h6>No data.</h6>
                <small>Try again.</small>
                <hr/>
                @endif
                @endforeach
            </div>
        </div>

result: searching works, but if empty I still dont have "No data."

ziben69 left a reply on Laravel | Problem With The Conditional Loop In The Search Engine

But if I do like this I have always No data. Hmm.

ziben69 left a reply on Laravel | Problem With The Conditional Loop In The Search Engine

 <div class="row">
            @foreach($results as $type => $list)
            @if (count($list) > 0)
            @foreach($list as $item)

            <div class="col-md-4" style="margin-bottom:10px;">
                <div class="card search-card">
                    <div class="card-body">
                        <strong class="card-title">
                            {{ $item->title}}
                        </strong>
                        {!! $item->description !!}
                    </div>
                </div>
            </div>
            @endforeach
            @else
            <hr/>
            <h6>No data.</h6>
            <small>Try again.</small>
            <hr/>
            @endif
            @endforeach  
        </div>

This one is partial view where $type = calendar. This one shows me not only the data from the calendar tabli but from all, the rest of the partialview are empty

ziben69 started a new conversation Laravel | Problem With The Conditional Loop In The Search Engine

Hello guys,

I have a small problem over which I sit all day without effect. I have a piece of code:

      <div class="row">
            @foreach($results as $type => $list)
            @if (count($list) > 0)
            @foreach($list as $item)

            <div class="col-md-4" style="margin-bottom:10px;">
                <div class="card search-card">
                    <div class="card-body">
                        <strong class="card-title">
                            {{ $item->title}}
                        </strong>
                        {!! $item->description !!}
                    </div>
                </div>
            </div>
            @endforeach
            @else
            <hr/>
            <h6>No data.</h6>
            <small>Try again.</small>
            <hr/>
            @endif
            @endforeach  
        </div>

More specifically, I mean a conditional loop, which checks if the list contains more than 0 elements.

@if (count($list) > 0)

By searching in the database, it works, but if the data is missing, I just have a blank white screen. The message "no data" should appear.

I tried a lot of combinations and still nothing. I tried to adjust the loop before foreach. I tried: sizeOf, Count,! Empty, $ list! == [] etc. It still does not work. Please help.

Here is my controller:

    public function search(Request $request)
    {
        $search = $request->get('search');
        $results = [];
        $results['calendar'] = Calendar::search($search)->paginate(5);
        $results['zone'] = Zone::search($search)->paginate(5);
        $results['tourism'] = Tourism::search($search)->paginate(5);
        $results['business'] = Business::search($search)->paginate(5);
        $results['culture'] = Culture::search($search)->paginate(5);
        $results['education'] = Education::search($search)->paginate(5);
        $results['inhabitant'] = Inhabitant::search($search)->paginate(5);
        $results['investor'] = Investor::search($search)->paginate(5);
        $results['senior'] = Senior::search($search)->paginate(5);
        $results['sport'] = Sport::search($search)->paginate(5);
        
        return view('pages.search', ['results' => $results]);
    }

and search.blade.php

        <div class="row">
            <div class="col-12 col-lg-4">
                @foreach($results as $type => $list)
                    @include('pages.search-results.'. $type, ['items' => $list])
        @endforeach
        </div>
        </div>

ziben69 left a reply on Search | How To Get Data From All Tables, Not Only One.

@REALRANDYALLEN - Hello,

it can't work because list is always !empty.

Look, in my $list are "Article" and "User" and these two values ​​always appear in the form of text.

21 Dec
1 month ago

ziben69 left a reply on Search | How To Get Data From All Tables, Not Only One.

That's it! and what if the search result is an empty array? At the moment I'm writing out all $ type without results. So I get headers: Articles, Users. How can I protect this with the conditional loop if?

@if (count($results) > 0)
@foreach($results as $type => $list)
       <h3>{{ $type }}</h3>
       <div class="single-contact-information mb-30">
       {{ $list }}
       @foreach($list as $item)
       {{ $item }}
       @endforeach  
       </div>
@endforeach
@else
       <hr/>
       <h6>No data.</h6>
       <small>Try again.</small>
       <hr/>
@endif

I have count($results) but now there will always be a search result like a $type

ziben69 left a reply on Search | How To Get Data From All Tables, Not Only One.

@LOSTDREAMER_NL - Hello @lostdreamer_nl,

I have just taken up this search engine. There is a small problem with returning the right view.

View [pages.search-results.calendars] not found.

Can you help me?

18 Dec
1 month ago

ziben69 left a reply on Laravel Blade | Hide If DB Data Doesn't Exists

Oo. Its so easy. Thanks mate!

Answer:

@forelse($metaList as $meta)                 
          @empty
          <div class="row">
                   <div class="col-lg-12">
                             <a href="{{ URL::to('meta/create') }}" class="btn btn-md btn-primary waves-effect waves-light"><i class="fas fa-plus-square"></i> Create</a><br><br>
                   </div>
         </div>
@endforelse 

ziben69 started a new conversation Laravel Blade | Hide If DB Data Doesn't Exists

Hello guys,

How can I hide div if rows doesn't exists?

No I have something like this:

@foreach($metaList as $meta)
@if (empty($meta->id))
       <div class="row">
              <div class="col-lg-12">
                    <a href="{{ URL::to('meta/create') }}" class="btn btn-md btn-primary waves-effect waves-light"><i class="fas fa-plus-square"></i> Create</a><br><br>
              </div>
        </div>
@endif
@endforeach

but it doesn't work :/ I need hide element when data doesn't exists and show when exists. Thanks for help.

14 Dec
1 month ago

ziben69 left a reply on File Upload - Failed To Open Stream: Permission Denied

But its generated by store() function. I have store('/files') only

ziben69 left a reply on File Upload - Failed To Open Stream: Permission Denied

I gave full permissions to the folder, but still the same. I put a project on the server and check if it works.

ziben69 started a new conversation File Upload - Failed To Open Stream: Permission Denied

Hello guys, I have problem with store file in my local storage

fopen(C:\xampp\htdocs\laravel\storage\app/public\public/storage/files/2g7cY5RytGcEiXLakZO1hw1hOpkVVRF8rTZCbYMd.): failed to open stream: Permission denied

three days ago everything worked, now that I'm suddenly testing the folder's lack of permissions, and the path to the file's destination looks like it looks.

What this is all about. How can I give write access to this folder?

12 Dec
1 month ago

ziben69 left a reply on Edit Column Data

Thanks for reply.

But what with edit only one column data from table?

ziben69 started a new conversation Edit Column Data

Hello guys,

I have a model that consists of three columns: site_title, site_description, keywords.

In list.blade.php I have list of "keywords":

 @foreach($metaList as $meta)
           <p class="card-text">{{ $meta->site_keywords }}</p>
           <a class="card-link" href="{{ URL::to('meta/edit/' . $meta->id) }}"><i class="fas fa-pencil-alt"></i>Edit</a>
           <a class="card-link" href="{{ URL::to('meta/delete/' . $meta->id ) }}" onClick="return confirm('Are you sure?')"><i class="fas fa-times"></i>Remove</a>
@endforeach

do I need to make 3 separate edit views to edit data from one column? Or I can do something other? Hmm, my logical thinking lies... Thanks!

10 Dec
1 month ago

ziben69 left a reply on Hide If File Doesn't Exist

@SERGIU17 - That's it. Thanks

ziben69 started a new conversation Hide If File Doesn't Exist

Hello guys, I have file.blade.php.

I need to hide empty files records in view:

 <div class="row">
      @foreach($files as $file)
      <div class="col-md-4" style="margin-bottom:10px;">
             <div class="card">
                     <div class="card-body">
                            <strong>{{ $file->title }}</strong>
                            <p class="card-text">
                                    {{ $file->created_at->diffForHumans() }}
                            </p>
                            <a href="{{ route('downloadSenior', $file->id) }}"><i class="fa fa-download" aria-hidden="true"></i> Download</a>
                     </div>
             </div>
      </div>
      @endforeach
</div>

How can I hide this part of view when file doesn't exist. Now I have empty links because in my DB are 30 rows without files. I should change:

$file->id

?? Thanks for help!

06 Dec
1 month ago

ziben69 started a new conversation Existing Laravel's Project On DirectAdmin Server

Hello guys, I neet to upload project on server with DirectAdmin, so I did:

  1. Upload project to public_html
  2. I moved files from the public folder to a level earlier
  3. I put the rest of the files in a different folder.
  4. I changed the paths in index.php
  5. I changed .env file
  6. I changed PHP version on server

Wouala! Index.php works, but subpages no.

I have tried the clear: cache and other commands from web.php Still nothing.

I have error, when I try go to subpages example www.domain.com/contact:

404
Not Found
The resource requested could not be found on this server!

What more can I do? Thanks so much.

04 Dec
1 month ago

ziben69 left a reply on Download File From Database (storage)

Ok I changed method move to storeAs. Now I have good file in directory named testfile.pdf, but still have problem with download:

File not found at path: C:/xampp/htdocs/tbg/storage/app/public/files/["testfile.pdf"]

probably because filename is an array, should I decode or sth?

ziben69 left a reply on Download File From Database (storage)

Oh thats it but now I have other error:

File not found at path: C:/xampp/htdocs/tbg/storage/app/public/files/["testfile.pdf"]

in storage/app/public/files directory I have file named "php37B4.tmp"

whaaat?

ziben69 started a new conversation Download File From Database (storage)

Hello guys,

I did multiple file upload: model File:

class File extends Model
{
    protected $fillable = [
        'title',
        'description',
        'filename'
    ];
}

FileController (store function):

  public function storeFiles(Request $request)
    {

        $this->validate($request, [
            'filename' => 'required',
            'filename.*' => 'mimes:doc,pdf,docx,zip'
        ]);


        if($request->hasfile('filename'))
        {
            foreach($request->file('filename') as $file)
            {
                $name=$file->getClientOriginalName();
                $file->move(storage_path('/app/public/files/', $name));
                $data[] = $name;  
            }
        }

        $file = new File();
        $file->title = $request->input('title');
        $file->description = $request->input('description');
        $file->filename=json_encode($data);   
        $file->save();

        return redirect()->action('[email protected]');
    }

and how can I download file now. I have something like this:

public function show($id)
    {
        $dl = File::find($id);
        return Storage::download(storage_path('app/public/files/'), $dl->filename);      
    }

but it gives to me error:

File not found at path: C:/xampp/htdocs/tbg/storage/app/public/files

and URL: http://localhost/filess/download/8

Can someone help me? Thanks

ziben69 left a reply on Store Multiple Files - Access Denied

Solved: the store function tried to save the file in the files directory located in the view folder. For others: do not call the view folder: files

ziben69 left a reply on Store Multiple Files - Access Denied

@LOSTDREAMER_NL - Still the same. Prohibited access :/

ziben69 started a new conversation Store Multiple Files - Access Denied

Hello guys, I try to do multiupload files. I have model File:

class File extends Model
{
    protected $fillable = [
        'title',
        'description',
        'filename'
    ];
}

FileController (function storeFiles):

public function storeFiles(Request $request)
    {

        $this->validate($request, [
            'filename' => 'required',
            'filename.*' => 'mimes:doc,pdf,docx,zip'
        ]);

        if($request->hasfile('filename'))
        {
            foreach($request->file('filename') as $file)
            {
                $name=$file->getClientOriginalName();
                $file->move(public_path().'/files/', $name);  
                $data[] = $name;  
            }
        }

        $file = new File();
        $file->title = $request->input('title');
        $file->description = $request->input('description');
        $file->filename=json_encode($data);   
        $file->save();

        return redirect()->action('[email protected]');
    }

and form:

 <form action="{{ action ('[email protected]')}}" method="POST"
                          enctype="multipart/form-data">
<input type="hidden" name="_token" value="{{csrf_token() }}"/>
<div class="form-group" style="position:relative">
         <input type="text" class="form-control" name="title" placeholder="Title" id="title" ><div id="headercount">255</div></span>
</div>
<div class="form-group" style="position:relative">
       <textarea class="form-control" rows="5" name="description" id="description"  placeholder="Description" maxlength="999" ></textarea>
</div>
<div class="form-group">
       <input type="file" id="filename" onchange="ValidateSize(this)" name="filename[]" multiple aria-describedby="fileHelp"/>
</div>
</form>

When I try to add a file, I get an error:


Prohibited access!
You do not have the right to access the desired directory. There is no index in the catalog or the catalog is protected against reading.

If you think this is a server error, please contact your administrator.

Error 403
localhost
Apache/2.4.33 (Win32) OpenSSL/1.1.0h PHP/7.2.6

I did:

php artisan storage:link

but it still doesn't work. Can you help me? Thanks.

03 Dec
1 month ago

ziben69 started a new conversation Search | How To Get Data From All Tables, Not Only One.

Hello guys,

I have function search:

public function search(Request $request)
    {
        $search = $request->get('search');
        $queries = DB::table('articles')->where('header', 'like', '%'.$search.'%')->paginate(5);
        return view('pages.search', ['queries' => $queries]);
    }

How can I take more data? Now I have data from only articles table, but need in the same search for example users -> name. Thanks

02 Dec
1 month ago

ziben69 left a reply on Displaying Data From The Table In All Views

Ok I did it! :)

Answer: view()->composer('*', function($view){ $current = Carbon::now(); $view->with('cal', Calendar::has('photos')->with('photos')->where('date','>=',$current)->orderBy('date', 'asc')->take(3)->get()); });

just changed 'pages.rollers.rollers' to '*'. It Works :)

ziben69 left a reply on Displaying Data From The Table In All Views

Ok, so I added in AppServiceProvider:

<?php

namespace App\Providers;

use App\Calendar;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\View;

class AppServiceProvider extends ServiceProvider
{
    public function boot()
    {
        view()->composer('rollers.rollers', function($view){
            $view->with('cal', Calendar::has('photos')->with('photos')->where('date','>=',$current)->orderBy('date', 'asc')->take(3)->get());
        });
    }

    public function register()
    {
        //
    }
}

something like this, but it still doesn't work.

What I do step by step:

  1. include rollers.blade.php in template.blade.php
@include('pages.rollers.rollers')
  1. Add view() in AppServiceProvider
  2. After click on contact.blade.php in Google Chrome I still have error:
Undefined variable: cal (View: C:\xampp\htdocs\tbg\resources\views\pages\rollers\rollers.blade.php)

In roller.blade.php I have something like this:

@foreach($cal as $calendar)
        <li><a href="{{ URL::to('calendar') }}"><b>{{ $calendar->header }}</b> <small>- {{ $calendar->date }}</small></a></li>
@endforeach

Someone can tell me what I do wrong?

ziben69 started a new conversation Displaying Data From The Table In All Views

Hello guys, i try to display data from one table in all views, but writing in each controller is very breakneck.

I created a view in which I display data from another table. I have displayed it in the template with include ('view'), but now that I pass between subpages, it throws an error with an unknown variable. Classic :/

rollers.blade.php:

<!-- Calendar's Roll (right) -->
       @foreach($calendars as $calendar)
       <li><a href="{{ URL::to('calendar') }}"><b>{{ $calendar->header }}</b> <small>- {{ $calendar->date }}</small></a></li>
       @endforeach

RollersController:

 public function index(CalendarRepository $calRepo)
    {
        $current = Carbon::now();
        $calendars = Calendar::has('photos')->with('photos')->where('date','>=',$current)->orderBy('date', 'asc')->take(3)->get();        
        return view('pages.rollers.rollers', compact('calendars'));
    }

template.blade.php

@include('pages.rollers.rollers')

I need do something like global variable? How can I solve this?

25 Nov
1 month ago

ziben69 left a reply on How To Secure File Uploads

@JAYTEE - If I change rules to:

return [
    'photos.*' => 'image|mimes:jpeg,bmp,png|max:2000',
    'header' => 'required|max:255',
    'description' => 'required',
    'date' => 'required',
]

I have the same:

No message

and I can upload nothing:

Class App\Http\Requests\UploadRequest does not exist

or I think wrong

ziben69 started a new conversation How To Secure File Uploads

Hello guys I have done tutorial to upload image files from link: https://laraveldaily.com/upload-multiple-files-laravel-5-4/

But how can I secure file uploads in view. Something like communicate when user will upload file more than 2MB?

Fragment of create.blade.php:

 <div class="form-group">
        <input type="file" name="photos[]" multiple aria-describedby="fileHelp"/>
        <small id="fileHelp" class="form-text text-muted">jpeg, png, bmp - 2MB.</small>
 </div>

and rules:

public function rules()
    {
        $rules = [
            'header' => 'required|max:255',
            'description' => 'required',
            'date' => 'required',
        ];
        $photos = $this->input('photos');
        foreach(range(0, $photos) as $index) {
            $rules['photos.' . $index] = 'image|mimes:jpeg,bmp,png|max:2000';
        }
 
        return $rules;
    }

all ok but when I try now to upload file which have got more than 2MB it gives me error:

Illuminate \ Http \ Exceptions \ PostTooLargeException
No message

How can I solve this? Thanks for help.

24 Nov
1 month ago

ziben69 left a reply on Save Calendar's Event With Photo (two Tables)

@RONALDJESSE - It work but not correct :P

i have 5 photos in Photo table, and when I create new calendar event it should create new record in Table Calendar and Table Photo with calendar_id. Now after click on button save it is editing existing record, and it is changing his calendar_id, but it should create new record in table with new calendar_id

23 Nov
1 month ago

ziben69 left a reply on Save Calendar's Event With Photo (two Tables)

I get photos in CalendarController function create, but how to store them in photo table which is in relationship with Calendar table

ziben69 started a new conversation Save Calendar's Event With Photo (two Tables)

Hello guys, I have a problem saving the photo when creating a calendar event. I have two tables in relationship calls: model Calendar

class Calendar extends Model
{
    protected $fillable = [
        'header','description','date'
    ];
    
      public function photos()
    {
        return $this->hasMany(Photo::class);   
    }

and model Photo: class Photo extends Model { protected $fillable = [ 'photoable_type','photoable_id','path','calendar_id' ];

public function calendar()
{
    return $this->belongsTo(Calendar::class, 'calendar_id');
}

}

my photos have calendar_id, i.e. one event can have many photos.

Here is CalendarController (create and store functions):

  public function create()
    {

        $photos = Photo::all();
        return view('pages.calendar.create', [
            "photos" => $photos
        ]);
    }

    public function store(Request $request)
    {
        $request->validate([
            'header' => 'required|max:255',
            'description' => 'required',
            'date' => 'required',
        ]);

        $calendar = new Calendar();
        $calendar->calendar_id = $request->input('photo'); <--- calendar_id is in the photo model
        $calendar->header = $request->input('header');
        $calendar->description = $request->input('description');
        $calendar->date = $request->input('date');
        $calendar->save();
    
        return redirect()->action('[email protected]');
    }

and here is a fragment of create.blade.php view:

<form action="{{ action ('[email protected]')}}" method="POST"
                          enctype="multipart/form-data">
                        <input type="hidden" name="_token" value="{{csrf_token() }}"/>
                        <div class="form-group">
                            <label for="photo">Photo:</label> <select class="form-control"
                                                                     name="photo"> 
                            @foreach($photos as $photo)
                            <option value="{{ $photo->id }}"><img class="img-responsive" src="{{ $photo->path }}"  style="width:100px; height:auto;"/></option>
                            @endforeach
                            </select>
                        </div>
                        <div class="form-group">
                            <label for="header">Header</label> <input type="text"
                                                                      class="form-control" name="header"/>
                        </div>
                        <div class="form-group">
                            <label for="description">Description</label><input type="text"
                                                                               class="form-control" name="description"/>
                        </div>
                        <div class="form-group">
                            <label for="date">Date</label> <input type="date"
                                                                  class="form-control" name="date"/>
                        </div>
                        <input type="submit" value="Create" class="btn btn-primary"/>
                    </form>

Error:

Column not found: 1054 Unknown column 'calendar_id' in 'field list' (SQL: insert into `calendars` (`calendar_id`, `header`, `description`, `date`, `updated_at`, `created_at`) values (204, asdsa, dsadsaasd, 1998-12-12, 2018-11-23 11:21:09, 2018-11-23 11:21:09))

I know that calendar_id is a column in Photo table, but how can I solve this?? I need to add photos from calendar's create view. Thanks for help.

22 Nov
2 months ago

ziben69 left a reply on Display One Photo For One Calendar's Event.

@BAHJAAT - Sorry, I forget about models. Edited