ziben69

ziben69

Member Since 1 Year Ago

Experience Points
5,290
Total
Experience

4,710 experience to go until the next level!

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

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

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

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

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

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

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

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

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

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

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

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

Level 2
5,290 XP
Oct
14
1 week ago
Activity icon

Replied to Laravel | Loop From 1 To N In Blade

Sorry friend, but you don't understand my question. I would like to display numbers from 1 to n in blade view. Only this...

I don't need to display sorted records.

For example I have 4 records in DB.

ID NAME 33 John 37 Ann 92 Dennis 104 Shon

Now I try to display names with numbers but something like that:

  1. John
  2. Ann
  3. Dennis
  4. Shon

How can I display numbers from 1 to n. Don't look at ID. I just need list with number 1,2,3,4,...,n. You understand now?

Activity icon

Replied to Laravel | Loop From 1 To N In Blade

$offers = Page::where('slug','oferta')->where('visible',1)->where('main',1)->with(['subpages'=>function($q) {
            $q->where('visible', 1)->where('main', 1)->take(6)->get();
        }])->has('subpages', '>', 0)->orderBy('order', 'asc')->get();

Here?

I think sortBy won't help because I configured the project so that many sugpage are assigned to one page. For another page, for example, I have reserved ID from 1-17, for the next from 18-23 etc. So "offer" page have from 33-n. I need there 1,2,3,4, ... , n numbers :/

Activity icon

Started a new Conversation Laravel | Loop From 1 To N In Blade

Hello guys, I have in my blade:

     @foreach($offers as $offer)
            @foreach($offer->subpages as $subpage)
            <div class="col-md-6 col-sm-6">
                <div class="feature-thumb">
                    <span>{{ $subpage->id }}</span>////// HERE IS A PROBLEM
                    <h3>{{ $subpage->title }}</h3>
                    <p>{{ $subpage->description }}</p>
                </div>
            </div>
            @endforeach
            @endforeach

and now I get results for example:

33 // <<<
John
Doe

84 // <<<
Ali
Baba

but how can I do it to get the result:

1 // <<<
John
Doe

2 // <<<
Ali
Baba

ID from 1-n?

Activity icon

Started a new Conversation Laravel | Pagination - Relationship Table Query

Hello guys, how can I use pagination, where my eloquent query looks:

PageController - method show:

$page = Page::where('slug', $slug)->with(['subpages'=>function($q) {
                $q->where('visible', 1)->orderBy('order', 'asc')->paginate(9);
}])->first();

I would like to paginate subpages on page's View blade (Page one to many Subpage relationship)

Here is part of my show.blade.php view:

{{ $page->subpages->links() }}

Error:

Method Illuminate\Database\Eloquent\Collection::links does not exist.
Oct
11
1 week ago
Activity icon

Replied to VueJS | What Should I Do Before Placing The Project On An External Server?

I have currently written a simple CMS in PHP (laravel) with the addition (for the first time) of Vue.JS. And that's where this question came from, because after every change in a component, I have to put the whole project back in again.

Oct
10
1 week ago
Activity icon

Started a new Conversation VueJS | What Should I Do Before Placing The Project On An External Server?

Hello guys, What should I do before placing the project on an external server?

This is a theoretical question because I want to avoid problems with subsequent rendering of components etc.

I currently have a project in phase: npm run watch. Should I change it to npm run production or what?

Thanks

Oct
08
1 week ago
Activity icon

Replied to Vue.JS | Doesn't Work On External Server.

Hmm, I noticed that a change is being made to the database. For example, I'm using tabble-draggable component. The position in the database changes, but it does not change in the view. The same is for example, hiding an item - the database changes in the view no. Even after refreshing the page.

For example:

 <th scope="col">Visiblity</th>
 <td v-if="page.visible !== null && page.visible===1">Yes</td>
 <td v-else>No</td>

In DB in table pages all my records have visiblity = 1, but in list.blade.view I see in column Visiblity "NO" in all records

Activity icon

Started a new Conversation Vue.JS | Doesn't Work On External Server.

Hello guys, on local server all is ok, but when I put project to external server not works. What I should do to run vue? I don't have errors in console :(

Activity icon

Started a new Conversation Laravel | Multiple Lightbox Gallery In One Blade's View

Hello guys I have problem. I try to get more than one lightbox gallery. Only one gallery is displayed at a time. The rest does not work, still trying to load photos, but not loading. I have a pages table that is relatively one-to-many linked to a subpages table. in pages view I display many subpages (including photos in galleries):

<div id="js-grid-lightbox-gallery" class="cbp ">
    @foreach($subpage->photos as $photo)
        <div class="cbp-item">
            <a href="/project/storage/app/{{ $photo->filename }}" class="cbp-caption cbp-lightbox" data-title="" rel="nofollow">
                <div class="cbp-caption-defaultWrap">
                    <img src="/project/storage/app/{{ $photo->filename }}" alt="">
                </div>
            </a>
        </div>
    @endforeach
</div>

I only get the gallery for the first subpage. How can I improve this code to display all galleries? Thanks!

Oct
05
2 weeks ago
Activity icon

Started a new Conversation Laravel | Bootstrap 4 Accordion - Open First Element

Hello guys, How can I set "show" class to first element of accordion's items? Now I have something like that:

<div class="row">
    <div class="col-md-12 mb40">
        @foreach($page->subpages as $subpage)
        @if($subpage->visible == "1" and $subpage->count() > 0 )
        <div id="accordion">
            <div class="card">
                <div class="card-header" id="headingOne">
                    <h5 class="mb-0">
                        <button class="btn btn-link" data-toggle="collapse" data-target="#collapse-{{ $subpage->id }}" aria-expanded="true" aria-controls="collapseOne">
                            {{ $subpage->title }}
                        </button>
                    </h5>
                </div>
                <div id="collapse-{{ $subpage->id }}" class="collapse  {{ (($subpage->id)=="1")? "show" : "" }}" aria-labelledby="headingOne" data-parent="#accordion">
                    <div class="card-body">
                        {!! $subpage->description !!}
                    </div>
                </div>
            </div>
        </div>
        @endif
        @endforeach
    </div>
</div>

This line works, but it's wrong idea.

<div id="collapse-{{ $subpage->id }}" class="collapse  {{ (($subpage->id)=="1") ? "show" : "" }}" aria-labelledby="headingOne" data-parent="#accordion">

Because when user will change subpage visiblity to false, it doesn't work. Hmm how can I solve this problem? How to write the condition correctly?

(($subpage->id)=="1")
Oct
02
2 weeks ago
Activity icon

Started a new Conversation Laravel | Generate PDF File From Blade View. Data From Relationship Tables

I have two tables Pages and Subpages in relationship one to many. In Subpages table I have page_id which is associated with the pages table id.

In my Page model I have:

 public function subpages(){
        return $this->hasMany(Subpage::class); 
 }

In PageController, function generatePDF:

    public function generatePDF(PageRepository $pageRepo, $id)
    {
        $page = $pageRepo->find($id);

        $title = $page->title;
        $subtitle = $page->subtitle;
        $description = $page->description;
        $subpage_title = $page->subpages()->title; /// I THINK HERE IS PROBLEM

        $data = [
            'title' => $title,
            'description' => $description,
            'subtitle' => $subtitle,
            'subpage_title' => $subpage_title, 
        ];
        $pdf = PDF::loadView('pages/page/' . $page->$id . '/myPDF', $data);

        return $pdf->download($title . '.pdf');
    }

How to display the assigned subpages?? I try in different ways, but I still get the error:

Property [title] does not exist on this collection instance.

Thanks for help!

Activity icon

Started a new Conversation Laravel | AppServiceProvider | Global Meta Head

Hey guys, I have question about meta in section head.

In sequence. When adding a record to the pages table, I provide data in the form - meta title, meta description and meta keywords.

Each page has its own meta tags. I'm trying to display corresponding meta tags on every page. at the moment I display all possible data (the same for each page).

AppServiceProvider:

// PAGE META
$view->with('pages_meta', Page::where('visible',1)->get());

View that I include in the template.blade.php:

@foreach($pages_meta as $pm)
<title>{{ $pm->site_title }}</title>
<meta name="description" content="{{ $pm->site_description }}">
<meta name="keywords" content="{{ $pm->site_keywords }}">
@endforeach

But how can I display data for specific page. Others on each page dedicated to the page. I suppose somehow I need to provide the page ID, but how? Thanks

Activity icon

Replied to Laravel | File Upload Validation

But without validation it works:

Here is my form:

<form action="{{ action ('[email protected]')}}" method="POST" enctype="multipart/form-data">
      <input type="hidden" name="_token" value="{{csrf_token() }}"/>
               <div class="form-row">
                      <div class="form-group col-md-12" id="photoInput">
                             <label>Images:</label>
                             <input type="file" id="uploadPhoto" onchange="ValidateSize(this)" name="photos[]" multiple aria-describedby="fileHelp"/>
                      </div>
               </div>
    <input type="submit" value="Dodaj" class="btn btn-primary"/>
</form>
Activity icon

Replied to Laravel | File Upload Validation

Hmm, error:

The "" file does not exist or is not readable.
Activity icon

Replied to Laravel | File Upload Validation

and how to check which mime of the file is returned?

Activity icon

Replied to Laravel | File Upload Validation

The photo is called test.JPG and has a size of 5MB, but this is only as part of the test if there is an error. Though a bootstrap alert should appear. This time it was error laravela (black screen)

But it's strange, because without validation I can easily save the file to the database

Activity icon

Replied to Laravel | File Upload Validation

so error code:

The photos must be an image.
The photos must be a file of type: jpeg, png, jpg, gif, svg.

When I remove this part of code

image|mimes:jpeg,png,jpg,gif,svg

it works, but this is not a good solution.

Oh, after removing part of the code, I tried to upload a file larger than 2048KB and I get an error from laravel:

fopen(C:\xampp\htdocs\project\public): failed to open stream: Permission denied
Activity icon

Replied to Laravel | File Upload Validation

So my code should looks like:

 request()->validate([
            'photos' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
]);

But it still not working... :(

Activity icon

Started a new Conversation Laravel | File Upload Validation

Hello again guys, I am trying to validate image upload with code:

PhotoController function store:

public function store(Request $request)
    {
        request()->validate([
            'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048', 
        ]);

        if ($request->has('photos')){
            foreach ($request->photos as $photo) {
                $filename = 'img-'.time().'.'.$photo->getClientOriginalExtension();
                $photo->storeAs('public/photos/',$filename);
                Photo::create([
                    'filename' => $filename
                ]);
            }
        }
        return redirect()->action('[email protected]');
    }

Part of blade's view:

@if (count($errors) > 0)
                    <div class="alert alert-danger">
                        <strong>Whoops!</strong> 
         There were problems adding the file.
         <ul>
         @foreach ($errors->all() as $error)
               <li>The size of a single photo should not exceed 1024KB.</li>
         @endforeach
         </ul>
</div>
@endif
@if(session('success'))
      <div class="alert alert-success">
      {{ session('success') }}
      </div> 
@endif

The error appears even when I try to upload a file with a size of 50KB. I am using XAMPP localhost server.

Activity icon

Started a new Conversation Laravel | Upload Multiple Photos

Hello again guys, I have small problem. I don't understand where I am making a mistake.

I have model Photo:

 protected $fillable = [
        'filename',
    ];

StoreController:

    public function store(Request $request)
    {
        $photo = Photo::create($request->all());

        if ($request->has('photos')){
            foreach ($request->photos as $photo) {
                $filename = 'img-'.time().'.'.$photo->getClientOriginalExtension();
                $photo->storeAs('public/photos/',$filename);
                Photo::create([
                    'filename' => $filename
                ]);
            }
        }
        return redirect()->action('[email protected]');
    }

and part of blade view:

<div class="form-row">
       <div class="form-group col-md-6" id="photoInput">
              <input type="file" id="uploadPhoto" onchange="ValidateSize(this)" name="photos[]" multiple aria-describedby="fileHelp"/>
       </div>
</div>

I get a negative result when I try to add images:

General error: 1364 Field 'filename' doesn't have a default value (SQL: insert into `photos` () values ())

As if I did not pass the name from the file selection field. Could someone explain to me where the error is in the function?

Thanks

Oct
01
2 weeks ago
Activity icon

Replied to Laravel | Copy To Clipboard Button

Thanks so much!

Activity icon

Started a new Conversation Laravel | Copy To Clipboard Button

Hello guys, I am trying to do copy to clipboard foreach loop.

<div class="row">
    @foreach($photos as $photo)
         <div class="col-md-3" style="padding:5px;">
              <div class="card">
                   <img src="/project/storage/app/{{ $photo->filename }}" class="card-img-top">
                   <div class="card-body">
                         <input type="text" id="copy_{{ $photo->id }}" value="{{ $photo->filename }}">
                         <button value="copy" onclick="copyToClipboard()">Copy!</button>
                  </div>
             </div>
      </div>
  @endforeach
</div>

and basic script:

<script>
    function copyToClipboard() {
        document.getElementById("copy_{{ $photo->id }}").select();
        document.execCommand('copy');
    }
</script>

Only at this time each button copies the filename of the last photo. How can I improve this piece of code so that each button matches my photo? Thanks!

Sep
29
3 weeks ago
Activity icon

Replied to Laravel | Remove File From Storage After Deleting The Row

>>> $document = Document::find(16);
=> App\Models\Document {#3043
     id: 16,
     subpage_id: 45,
     filename: "dokument1569770228.docx",
>>> public_path('documents/' . $document->filename)
=> "C:\xampp\htdocs\project\public\documents/dokument1569770228.docx"

I see wrong slash beetwen documents and filename hmm. Lets try to change it

hmm. Btw maybe I should try run project on external server?

Activity icon

Replied to Laravel | Remove File From Storage After Deleting The Row

@sergiu17

dd('public/documents/' . $document->filename); 

does not respond

@snapey I tested, but no effect

Activity icon

Replied to Laravel | Remove File From Storage After Deleting The Row

I was glad too soon hehe. After deleting the record, the file is still in directory public/documents hmm.

My code now:

  public function delete(SubpageRepository $subRepo, $id)
    {
        $subpage = $subRepo->find($id);

        foreach($subpage->documents() as $document) {
            if(file_exists('public/documents/' . $document->filename)) {
                unlink('public/documents/' . $document->filename);
            }
        }

        $subpage->documents()->delete();

        $subpage = $subRepo->delete($id);
        return redirect()->action('[email protected]');
    }
Activity icon

Started a new Conversation Laravel | Remove File From Storage After Deleting The Row

Hello, i am trying to remove file from storage. currently, I only delete data from the database, but I care about deleting the file completely. What can I do? Here is my code:

Delete function:

 public function delete(SubpageRepository $subRepo, $id)
    {
        $subpage = $subRepo->find($id);
        $subpage->documents()->delete();
        Storage::delete('/public/documents/'.$subpage->documents);  ////////////// HERE
        $subpage = $subRepo->delete($id);
        return redirect()->action('[email protected]');
    }

Model Document:

    protected $fillable = [
        'filename',
        'subpage_id',
    ];
    public $timestamps = false;
    public function subpage()
    {
        return $this->belongsTo(Subpage::class, 'subpage_id');
    }
Activity icon

Replied to Laravel | File Upload. Problem With Saving Into Database

Could you tell me if it's better to use::

$filename = $document->getClientOriginalName();

or

$filename = 'filename'.time().'.'.$document->getClientOriginalExtension();

???

Activity icon

Started a new Conversation Laravel | File Upload. Problem With Saving Into Database

Hello guys, I am trying to upload file, and save into DB (in table documents)

Model Document:

class Document extends Model
{
    protected $fillable = [
        'filename',
        'subpage_id',
    ];
    protected $appends = ['path'];

    public function getPathAttribute()
    {
        return asset('caritas/storage/app/'.$this->filename);
    }

    public $timestamps = false;

    public function subpage()
    {
        return $this->belongsTo(Subpage::class, 'subpage_id');
    }
}

ForeignKey:

Schema::table('documents', function(Blueprint $table){
            $table->integer('subpage_id')->unsigned()->change();
            $table->foreign('subpage_id','documents_subpage_id_foreign')->references('id')->on('subpages');
});

Function Store in SubpageController:

 public function store(Request $request)
    {
        $subpage = Subpage::create($request->all());
      
        if ($request->has('documents')){
            foreach ($request->documents as $document) {

                $request->validate([
                    'documents' => 'required|file|max:1024',
                ]);

                $filename = "filename".time().'.'.request()->documents->getClientOriginalExtension();

                $request->documents->storeAs('public/documents',$filename);

                Document::create([
                    'subpage_id' => $subpage->id,
                    'filename' => $filename
                ]);
            }
        }
        return redirect()->action('[email protected]');
    }

fragment of create.blade.php view:

 <input type="file" id="uploadDocument" onchange="ValidateFileSize(this)" name="documents[]" multiple aria-describedby="fileHelp"/>

and route:

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

I'm not sure, but it's probably the controller function problem. I don't get any error, but the file is not saved in the database. I have empty records Could someone help me figure out where I am making a mistake? Thanks.

Activity icon

Replied to Laravel | Routing Overlapping Problem

you were right :) Thanks :)

Activity icon

Started a new Conversation Laravel | Routing Overlapping Problem

Hello guys,

I have problem with route overlapping. When I try to display contact.blade.php I am getting an error message:

Trying to get property 'title' of non-object (View: C:\xampp\htdocs\project\resources\views\pages\page\show.blade.php)

Page show function route

Route::get('/{slug}', '[email protected]');

Contact index function route

Route::get('contact/', '[email protected]');

How can I solve this problem?

Sep
27
3 weeks ago
Activity icon

Replied to Laravel | Routing - Find Row By $slug And Display Data In Blades View

Answer:

$page = Page::where('slug', $slug)->first();

Thanks, sorry for littering

Activity icon

Started a new Conversation Laravel | Routing - Find Row By $slug And Display Data In Blades View

Hey guys, I have question, how can I display data from table. (I have in my table column SLUG). When I pass id instead of slug, it's ok. Slug is created based on the title when adding an item to the table Here is my code:

web.php

Route::get('/{slug}', '[email protected]');

Controller (function show):

public function show(PageRepository $pageRepo, $slug){
        $page = $pageRepo->find($slug);
        return view('pages.page.show', [
            "page" => $page
        ]);
}

View:

{{ $page->title }}

Error:

Trying to get property 'title' of non-object

Can anyone tell me why he doesn't get the title?

Activity icon

Started a new Conversation Eloquent | Relationship With And Where Clause Based On Foreign Column

Hello guys,

I have question. I try to display records with visible status TRUE. I have two tables: groups and pages. In both is the same column: VISIBLE, and I am trying something like that:


view()->composer('*', function($view){
   $view->with('topbar_group', Group::where('visible',1)->orderBy('order', 'asc')->with(['pages'])->whereHas('pages', 
       function($q) {
            $q->where('visible', '=',1);
       })->get());

This part works good:

Group::where('visible',1)->orderBy('order', 'asc')->with(['pages'])

But my function with $parameter not working, I think problem is here $q->where('visible', '=',1);. How can I solve this problem. Thanks for any solutions :)

Activity icon

Started a new Conversation Extracting Data From The Relational Table To The AppServiceProvider

I have two tables GROUPS and PAGES in relationship One Group to many Pages. The tables are linked together using group_id (in pages table). The current code allows me to display the names of all groups, but not to display pages assigned to a particular group.

Model Group:

class Group extends Model
{
    protected $fillable = [
        'title',
        'navbar_id',
    ];

     public function pages()
    {
        return $this->hasMany(Page::class);   
    }
}

Model Page:

class Page extends Model
{
    protected $fillable = [
        'title',
        'group_id'
    ];    
    public function groups()
    {
        return $this->belongsTo(Group::class, 'group_id');
    }

ForeignKey:

public function up()
    {
        Schema::table('pages', function(Blueprint $table){
            $table->integer('group_id')->unsigned()->change();
            $table->foreign('group_id','pages_group_id_foreign')->references('id')->on('groups');
        });
    }

AppServiceProvider:

view()->composer('*', function($view){
            $view->with('topbar', Group::where('visible',1)->with(['pages'])->get());
});

and fragment of View:

@foreach($topbar as $group)
<li class="nav-item dropdown">
   <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#">{{ $group->title }}</a>
   <ul class="dropdown-menu">
      @foreach($group->pages() as $page)
      <li class="">
         <a href="#" class="dropdown-item">{{ $page->title }}</a>
      </li>
      @endforeach
   </ul>
</li>
@endforeach
Sep
26
3 weeks ago
Activity icon

Replied to Laravel | Generate PDF | Data From Relationship

pages table is in relationship with subpages - one page to many subpages.

Page Model:

 public function subpages()
    {
        return $this->hasMany(Subpage::class); 
    }

Subpage Model:

  public function pages()
    {
        return $this->belongsTo(Page::class, 'page_id');
    }

when creating a subpage, I choose a page from the combobox. Page_id is automatically saved to the subpage table.

So in my table subpages I have column page_id.

I need to display all subpages having page_id the same as the page id from which the PDF is generated

my id of Page is in $page variable, but how to check now which subpage have page_id = id of Page?

Activity icon

Replied to Laravel | Generate PDF | Data From Relationship

but this is about the title of the subpages, if I delete them everything is ok

Activity icon

Started a new Conversation Laravel | Generate PDF | Data From Relationship

Hello guys, I have two tables PAGES, and SUBPAGES

I am trying to generate PDF from Pages view (all works), but how to get data from table subpages. I have something like that:

PageController | Function GeneratePDF:

 public function generatePDF(PageRepository $pageRepo, $id)
    {
        $page = $pageRepo->find($id)->with(['videos', 'photos', 'subpages']);
       

        $title = $page->title;
        $subtitle = $page->subtitle;
        $description = $page->description;
        $subpage_title = $page->subpages()->title; /////////////// THIS ONE

        $data = ['title' => $title,
                 'description' => $description,
                 'subtitle' => $subtitle,
                 'subpage_title' => $subpage_title, 
                ];
        $pdf = PDF::loadView('pages/page/' . $page->$id . '/myPDF', $data);

        return $pdf->download($title . '.pdf');
    }

myPDF view:

<!DOCTYPE html>
<html>
    <head>
        <title></title>
    </head>
    <body>
        <h1>{{ $title }}</h1>
        <h2>{{ $subtitle }}</h2>
        <p>{{ $description }}</p>
        
        <h3>{{ $subpage_title }}</h3> /////////// AND HERE
    </body>
</html>

My error:

Property [title] does not exist on the Eloquent builder instance.
Sep
25
3 weeks ago
Activity icon

Replied to Laravel + Tinymce - Works Only On App.blade.php

Ok I used CKEditor4. Works good ;)

Activity icon

Replied to Laravel + Tinymce - Works Only On App.blade.php

Here is my app.blade.php:

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <!-- CSRF Token -->
        <meta name="csrf-token" content="{{ csrf_token() }}">

        <!-- Scripts -->
        <script src="{{ asset('js/app.js') }}"></script>
        <script src="{{ asset('js/admin.js') }}"></script>

        <!-- Fonts -->
        <link rel="dns-prefetch" href="https://fonts.gstatic.com">
        <link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet" type="text/css">

        
        <!-- Styles -->
        <link href="{{ asset('css/app.css') }}" rel="stylesheet">
        <link href="{{ asset('css/layout-styles.css') }}" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css"      
        rel="stylesheet" type="text/css">
        <!--Dynamic StyleSheets added from a view would be pasted here-->
        @yield('styles')
    </head>
    <body>
        <div id="app">
            <nav class="navbar navbar-expand-md navbar-light navbar-laravel">
              ...
            </nav>
            <div class="py-5">
                @yield('content')
            </div>
        </div>

        <textarea class="description" name="description"></textarea>  //////////////////////////////THIS ONE WORKS
        <script src="https://cdn.tiny.cloud/1/API KEY/tinymce/5/tinymce.min.js"></script>
        <script>
            tinymce.init({
                selector:'textarea.description',
                width: 900,
                height: 300
            });
        </script>
        @yield('scripts')

    </body>
</html>

And for example one of my views that uses TinyMCE:

@extends('layouts.app') @section('content')

<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-12">
            <!-- Page-Title -->
                    <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">
                            <label for="description">Description:</label>
                            <textarea class="description" name="description"></textarea> /////////////////// HERE IS TinyMCE EDITOR - NOT WORKING
                        </div>
                        <input type="submit" value="Create" class="btn btn-primary"/>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection('content')

the editor is displayed on all views but is locked on other views than app.blade.php

Activity icon

Started a new Conversation Laravel + Tinymce - Works Only On App.blade.php

Hello guys, I have added TinyMCE wysiwyg editor to my project, but I have a problem.

When I add TinyMCE to my main template view App.blade.php like that (on bottom of body):

<textarea class="description" name="description"></textarea>
        <script src="https://cdn.tiny.cloud/1/APIKEY/tinymce/5/tinymce.min.js"></script>
<script>
     tinymce.init({
       selector:'textarea.description',
       width: 900,
       height: 300
     });
</script>

Is all OK but only on main template view, in other views for example create.blade.php I have a non-clickable TinyMCE editor's window. And I cant there nothing to click, write etc. In console I don't have any errors. Can you help me solve this problem. How to this share script on all views?

Sep
24
3 weeks ago
Activity icon

Started a new Conversation Laravel | Store Data From Combobox In DB. Two Tables In One Combobox.

Hey guys I have question: how to store data in DB from combobox, when there are options from two tables.

I have something like that:

Table: Navbar, Table: Group, Table: Page

Navbar is in relationship with Page - one to many - with navbar_id Group is in relationship with Page - one to many - with group_id

create.blade.php - Page's view

<select class="form-control" name="navbar_id"> 
       @foreach($navs as $nav)
            <option value="{{ $nav->id }}">{{ $nav->title }}</option>
       @endforeach
       @foreach($groups as $group)
            <option value="{{ $group->id }}">{{ $group->title }}</option>
       @endforeach
</select>

and now I have problem with saving in DB because select's name is navbar_id, but how can I add group_id. maybe JS function which change name or something? Thanks for help!

Sep
22
4 weeks ago
Activity icon

Replied to Laravel | How To Display Selected Value In Combobox From Related Table

king of gold! Works, thank you. Now I will try to understand your implementation. Thank you very much!

Activity icon

Replied to Laravel | How To Display Selected Value In Combobox From Related Table

Ok, added. I have now in my PageRepository function:

 public function findWithNavbar($id){
        return Page::with('navbars')->find($id);
 }

and changed in Controller:

 public function edit(PageRepository $pageRepo, $id)
    {
        $page = $pageRepo->findWithNavbar($id);
        $navs = Navbar::all();
 
        return view('pages.page.edit', [
            "page" => $page,
            "navs" => $navs
        ]);
    }

but I still don't know how to enter the navbar_id value contained in the record from the pages table (the navbar title is stored in the navbar table) to combobox

Activity icon

Started a new Conversation Laravel | How To Display Selected Value In Combobox From Related Table

Hello guys I have question:

I have 2 models in relationship:

Model Navbar and Model Page, one navbar have many pages. In page's edit.blade.php view I have combobox:

<select class="form-control" name="navbar_id">
       @foreach($navs as $nav)
       <option value="{{ $nav->id }}">{{ $nav->title }}</option>
       @endforeach
</select>

Here is my PageController:

  public function edit(PageRepository $pageRepo, $id)
    {
        $page = $pageRepo->find($id);
        $navs = Navbar::all();

        return view('pages.page.edit', [
            "page" => $page,
            "navs" => $navs
        ]);
    }

I am currently displaying all records from the navbars table. How do you get the value assigned in the record from the database?

Activity icon

Replied to Laravel | Radio Buttons - Edit View - Get Checked Value

Answer:

...
<input type="radio" name="layout" value="2col-img-sidebar" {{ ($page->layout=="2col-img-sidebar")? "checked" : "" }}>
...