raygun

raygun

Member Since 4 Years Ago

Experience Points
7,045
Total
Experience

2,955 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
46
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
7,045 XP
Nov
20
3 years ago
Activity icon

Replied to Call To Undefined Method Illuminate\Database\Query\Builder::currentPage()

@JoeDawson not silly at all. I deleted the following.

                    {{-- Reverse direction --}}
                    @if ($reverse_direction)
                        @if ($posts->currentPage() > 1)
                            <li class="previous">
                                <a href="{!! $posts->url($posts->currentPage() - 1) !!}">
                                    <i class="fa fa-long-arrow-left fa-lg"></i>
                                    Previous {{ $tag->tag }} Posts
                                </a>
                            </li>
                        @endif
                            @if ($posts->hasMorePages())
                                <li class="next">
                                    <a href="{!! $posts->nextPageUrl() !!}">
                                        Next {{ $tag->tag }} Posts
                                        <i class="fa fa-long-arrow-right"></i>
                                    </a>
                                </li>
                            @endif
                     @else
                        @if ($posts->currentPage() > 1)
                            <li class="previous">
                                <a href="{!! $posts->url($posts->currentPage() - 1) !!}">
                                    <i class="fa fa-long-arrow-left fa-lg"></i>
                                    Newer {{ $tag ? $tag->tag : '' }} Posts
                                </a>
                            </li>
                        @endif
                            @if ($posts->hasMorePages())
                                <li class="next">
                                    <a href="{!! $posts->nextPageUrl() !!}">
                                        Older {{ $tag ? $tag->tag : '' }} Posts
                                        <i class="fa fa-long-arrow-right"></i>
                                    </a>
                                </li>
                            @endif
                      @endif
                </ul>
    

    the error is gone

Activity icon

Started a new conversation Call To Undefined Method Illuminate\Database\Query\Builder::currentPage()

I keep getting the following error

Call to undefined method Illuminate\Database\Query\Builder::currentPage()

heres my code

@extends('blog.layouts.master')

    @section('page-header')
        <header class="intro-header"
                style="background-image: url('{{ page_image($page_image) }}')" id="hero">
            <div class="container">
                <div class="row">
                    <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                        <div class="site-heading">
                            <h1>{{ $title }}</h1>
                            <hr class="small">
                            <h2 class="subheading">{{ $subtitle }}</h2>
                        </div>
                    </div>
                </div>
            </div>
        </header>
    @stop
    
    @section('content')
        <div class="container">
            <div class="row">
                <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
    
                    {{-- The Posts --}}
                    @foreach ($posts as $post)
                        <div class="post-preview">
                            <a href="{{ $post->url($tag) }}">
                                <h2 class="post-title">{{ $post->title }}</h2>
                                @if ($post->subtitle)
                                    <h3 class="post-subtitle">{{ $post->subtitle }}</h3>
                                @endif
                            </a>
                            <p class="post-meta">
                                Posted on {{ $post->published_at->format('F j, Y') }}
                                @if ($post->tags->count())
                                    in
                                    {!! join(', ', $post->tagLinks()) !!}
                                @endif
                            </p>
                        </div>
                        <hr>
                    @endforeach
    
                    {{-- The Pager --}}
                    <ul class="pager">
    
                        {{-- Reverse direction --}}
                        @if ($reverse_direction)
                            @if ($posts->currentPage() > 1)
                                <li class="previous">
                                    <a href="{!! $posts->url($posts->currentPage() - 1) !!}">
                                        <i class="fa fa-long-arrow-left fa-lg"></i>
                                        Previous {{ $tag->tag }} Posts
                                    </a>
                                </li>
                            @endif
                                @if ($posts->hasMorePages())
                                    <li class="next">
                                        <a href="{!! $posts->nextPageUrl() !!}">
                                            Next {{ $tag->tag }} Posts
                                            <i class="fa fa-long-arrow-right"></i>
                                        </a>
                                    </li>
                                @endif
                         @else
                            @if ($posts->currentPage() > 1)
                                <li class="previous">
                                    <a href="{!! $posts->url($posts->currentPage() - 1) !!}">
                                        <i class="fa fa-long-arrow-left fa-lg"></i>
                                        Newer {{ $tag ? $tag->tag : '' }} Posts
                                    </a>
                                </li>
                            @endif
                                @if ($posts->hasMorePages())
                                    <li class="next">
                                        <a href="{!! $posts->nextPageUrl() !!}">
                                            Older {{ $tag ? $tag->tag : '' }} Posts
                                            <i class="fa fa-long-arrow-right"></i>
                                        </a>
                                    </li>
                                @endif
                          @endif
                    </ul>
                </div>
    
            </div>
        </div>
    @stop

and currentPage is defined

Nov
17
3 years ago
Activity icon

Replied to Tags Won't Work Unless I Remove Search Capability And Vice Versa

@thomaskim I'm in the process of fixing it. for some reason it won't format correctly

Activity icon

Started a new conversation Tags Won't Work Unless I Remove Search Capability And Vice Versa

Tags won't work unless I remove search capability and vice versa. I've followed a tutorial which I've tried to modify to suit my blogs needs. The app already had the ability to search tags. The code looks like the following

 public function index(Request $request)
{
        $tag = $request->get('tag');
        $data = $this->dispatch(new TagIndexData($tag));
        $layout = $tag ? Tag::layout($tag) : 'tags.layouts.index';

        return view($layout, $data);

}

I've modified it, by adding a search capability and the code looks like the following

    public function index(Request $request)
{
    $query = $request->get('q');

    $posts = Post::where('title', 'LIKE', "%{$query}%")
            ->orwhere('subtitle', 'LIKE', "%{$query}%")->get();

    $videos = Video::where('title', 'LIKE', "%{$query}%")
        ->orwhere('subtitle', 'LIKE', "%{$query}%")->get();

        $tag = $request->get('tag');
        $data = $this->dispatch(new TagIndexData($tag));
        $layout = $tag ? Tag::layout($tag) : 'tags.layouts.index';

        return view($layout, $data)->withPosts($posts)->withVideos($videos);

}

When I modify it, the search works but the ability to use the tags no longer works. When I click on a tag, it returns everything Also here is my TagIndexData

<?php
    namespace App\Jobs;

    
use App\Post;
    
use App\Video;
    
use App\Tag;
    
use Carbon\Carbon;
    
use Illuminate\Contracts\Bus\SelfHandling;

    
class TagIndexData extends Job implements SelfHandling
    {
        
protected $tag;

    
        
public function __construct($tag)
 {
            
$this->tag = $tag;
        
}

    
        
public function handle()
 {
   
if ($this->tag) {
   
return $this->tagIndexData($this->tag);
        
}

        
return $this->normalIndexData();
        
}



protected function normalIndexData()
        
{
        
    $posts = Post::with('tags')
->where('published_at', '<=', Carbon::now())
    ->where('is_draft', 0)

    ->orderBy('published_at', 'desc')
    ->simplePaginate(config('blog.posts_per_page'));

        

$videos = Video::with('tags')
->where('published_at', '<=', Carbon::now())
            
->where('is_draft', 0)

->orderBy('published_at', 'desc')

 ->simplePaginate(config('blog.posts_per_page'));

  
 return [
            
   'title' => config('tags.title'),
  
    'subtitle' => config('tags.subtitle'),
           
     'posts' => $posts,
 
   'videos' => $videos,
            
   'page_image' => config('home.page_image'),
            
    'meta_description' => config('home.description'),
            
    'reverse_direction' => false,
            'tag' => null,
        
    ];
    
}
    
    protected function tagIndexData($tag)
    
    {
        
        $tag = Tag::where('tag', $tag)->firstOrFail();
        
    $reverse_direction = (bool)$tag->reverse_direction;


        
    $posts = Post::where('published_at', '<=', Carbon::now())
            
        ->whereHas('tags', function ($q) use ($tag) 
    {
                
        $q->where('tag', '=', $tag->tag);
            
    })
            ->where('is_draft', 0)
            
    ->orderBy('published_at', $reverse_direction ? 'asc' : 'desc')
            
    ->simplePaginate(config('blog.posts_per_page'));
        
    $posts->addQuery('tag', $tag->tag);


        
    $videos = Video::where('published_at', '<=', Carbon::now())
            
    ->whereHas('tags', function ($q) use ($tag) {
                
        $q->where('tag', '=', $tag->tag);
            
    })
            
    ->where('is_draft', 0)
            
    ->orderBy('published_at', $reverse_direction ? 'asc' : 'desc')
           
     ->simplePaginate(config('blog.posts_per_page'));
        
        $videos->addQuery('tag', $tag->tag);


       
         $page_image = $tag->page_image ?: config('tags.page_image');


        
        return [
           
             'title' => $tag->title,
            
            'subtitle' => $tag->subtitle,
            
            'posts' => $posts,
           
             'videos' => $videos,
          
              'page_image' => $page_image,
           
             'tag' => $tag,
           
             'reverse_direction' => $reverse_direction,
            
            'meta_description' => $tag->meta_description ?:
 config('blog.description'),
            
        ];
       
     }
    
}

                
                
Nov
13
3 years ago
Activity icon

Started a new conversation Php Artisan Tinker Is Not Working

When I try run phpnartisan tinker I get the follwing error That I have never seen before

PsySH history file found at '/home/vagrant/.config/psysh_history'. Please delete it or move it to '/home/vagrant/.config/psysh/psysh_history'. 

I tried looking for this file and don't know where it is

Sep
25
4 years ago
Activity icon

Started a new conversation What Does This Mean Call To Undefined Method Illuminate\Database\Query\Builder::tags()

Not understanding why I am gettin the following error.

    Call to undefined method Illuminate\Database\Query\Builder::tags()

any help would be appreciated

Sep
23
4 years ago
Activity icon

Started a new conversation My Tag Query Is Returning All The Entries Instead Of The Selected Tags

All the entries are being returned instead of only the ones that match the tag selected. Not sure why. It was working before my tag index data

<?php
    
    namespace App\Jobs;
    
    use App\Post;
    use App\Video;
    use App\Tag;
    use Carbon\Carbon;
    use Illuminate\Contracts\Bus\SelfHandling;
    
    class TagIndexData extends Job implements SelfHandling
    {
        protected $tag;
    
        /**
         * Constructor
         *
         * @param string|null $tag
         */
        public function __construct($tag)
        {
            $this->tag = $tag;
        }
    
        /**
         * Execute the command.
         *
         * @return array
         */
        public function handle()
        {
            if ($this->tag) {
                return $this->tagIndexData($this->tag);
            }
    
            return $this->normalIndexData();
        }
    
        /**
         * Return data for normal index page
         *
         * @return array
         */
        protected function normalIndexData()
        {
            $posts = Post::with('tags')
                ->where('published_at', '<=', Carbon::now())
                ->where('is_draft', 0)
                ->orderBy('published_at', 'desc')
                ->simplePaginate(config('blog.posts_per_page'));
    
            $videos = Video::with('tags')
                ->where('published_at', '<=', Carbon::now())
                ->where('is_draft', 0)
                ->orderBy('published_at', 'desc')
                ->simplePaginate(config('blog.posts_per_page'));
    
            return [
                'title' => config('tags.title'),
                'subtitle' => config('tags.subtitle'),
                'posts' => $posts,
                'videos' => $videos,
                'page_image' => config('home.page_image'),
                'meta_description' => config('home.description'),
                'reverse_direction' => false,
                'tag' => null,
            ];
        }
        /**
         * Return data for a tag index page
         *
         * @param string $tag
         * @return array
         */
        protected function tagIndexData($tag)
        {
            $tag = Tag::where('tag', $tag)->firstOrFail();
            $reverse_direction = (bool)$tag->reverse_direction;
    
    
            $posts = Post::where('published_at', '<=', Carbon::now())
                ->whereHas('tags', function ($q) use ($tag) {
                    $q->where('tag', '=', $tag->tag);
                })
                ->where('is_draft', 0)
                ->orderBy('published_at', $reverse_direction ? 'asc' : 'desc')
                ->simplePaginate(config('blog.posts_per_page'));
            $posts->addQuery('tag', $tag->tag);
    
    
            $videos = Video::where('published_at', '<=', Carbon::now())
                ->whereHas('tags', function ($q) use ($tag) {
                    $q->where('tag', '=', $tag->tag);
                })
                ->where('is_draft', 0)
                ->orderBy('published_at', $reverse_direction ? 'asc' : 'desc')
                ->simplePaginate(config('blog.posts_per_page'));
            $videos->addQuery('tag', $tag->tag);
    
    
            $page_image = $tag->page_image ?: config('tags.page_image');
    
    
            return [
                'title' => $tag->title,
                'subtitle' => $tag->subtitle,
                'posts' => $posts,
                'videos' => $videos,
                'page_image' => $page_image,
                'tag' => $tag,
                'reverse_direction' => $reverse_direction,
                'meta_description' => $tag->meta_description ?:
                    config('blog.description'),
            ];
        }
    }

my tag controller

<?php
    
    namespace App\Http\Controllers;
    
    use App\Jobs\TagIndexData;
    use Illuminate\Http\Request;
    use App\Http\Requests;
    use App\Post;
    use App\Video;
    use App\Tag;
    use App\Http\Controllers\Controller;
    
    class TagController extends Controller
    {
        public function index(Request $request)
        {
            $query = $request->get('q');
    
            $posts = Post::where('title', 'LIKE', "%{$query}%")
                    ->orwhere('subtitle', 'LIKE', "%{$query}%")->get();
    
            $videos = Video::where('title', 'LIKE', "%{$query}%")
                ->orwhere('subtitle', 'LIKE', "%{$query}%")->get();
    
                $tag = $request->get('tag');
                $data = $this->dispatch(new TagIndexData($tag));
                $layout = $tag ? Tag::layout($tag) : 'tags.layouts.index';
    
                return view($layout, $data)->withPosts($posts)->withVideos($videos);
    
        }
    }

my tag index view

@extends('tags.layouts.master')
    
    @section('page-header')
        <header class="intro-header"
                style="background-image: url('{{ pathway($page_image) }}'); height: 470px"> {{--set height so pic wont jump--}}
            <div class="container">
                <div class="row">
                    <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                        <div class="site-heading">
                            <h1>{{ $title }}</h1>
                            <hr class="small">
                            <h2 class="subheading">{{ $subtitle }}</h2>
                        </div>
                    </div>
                </div>
            </div>
        </header>
    @stop
    
    @section('content')
        <div style="width: 80%; margin: 0 auto">
            {{-- The Posts ------------------------------------------------------------------}}
            <div style="background-color:#2f3037"><h1 style="color: #f5f5f5">News</h1></div>
            @if ($posts->count())
                <div class="scroll">
                    @foreach ($posts as $post)
                        <div class="post-preview" id="box">
                            <a href="{{ $post->url($tag) }}">
                                <h2 class="post-title">{{ str_limit($post->title, 10) }}</h2>
                                @if ($post->subtitle)
                                    <h3 class="post-subtitle">{{ $post->subtitle }}</h3>
                                @endif
                            </a>
                            <p class="post-meta">
                                Posted  {{ $post->published_at->format('m.d.y') }}
                                @if ($post->tags->count())
                                    in
                                    {!! join(', ', $post->tagLinks()) !!}
                                @endif
                            </p>
                            <hr>
                        </div>
                    @endforeach
                    @else
                        <h1 style="text-align: center">no posts match your search</h1>
                    @endif
                </div>
                {{-- End Posts ------------------------------------------------------------------}}
    
    
                {{-- The Videos --}}
                <div style="background-color:red; width:1024px; margin:0 auto"><h1>Videos</h1></div>
                @if ($videos->count())
                    <div class="scroll">
                        @foreach ($videos as $video)
                            <div class="post-preview" id="box">
                                <a href="{{ $video->url($tag) }}">
                                    <h2 class="post-title">{{ $video->title }}</h2>
                                    @if ($video->subtitle)
                                        <h3 class="post-subtitle">{{ str_limit($video->subtitle, 20) }}</h3>
                                    @endif
                                </a>
                                <p class="post-meta">
                                    Posted on {{ $video->published_at->format('m.d.y') }}
                                    @if ($video->tags->count())
                                        in
                                        {!! join(', ', $video->tagLinks()) !!}
                                    @endif
                                </p>
                            </div>
                            <hr>
                        @endforeach
    
                        @else
                            <h1 style="text-align: center">no videos match your search</h1>
                        @endif
    
                    </div>
                    {{-- End videos --}}
        </div>
    @stopa

I can not understand how this has just stopped working any help would be appreciated.

Sep
10
4 years ago
Activity icon

Replied to I Keep Getting This Error In_array() Expects Parameter 2 To Be Array, Null Given

Thanks @luoshiben ever since I had a package break on me and the author said he's not going to fix it any time soon, I shied away from packages. I never really liked using them from the jump. I have no problem trying to learn how my self and with some guidance from forums like this. Thanks for the input. I am following a tutorial. this is not my own code. I am pretty much still in the novice stages. But thanks for your input. I't worked. I no globals are bad But I wouldn't even know how to structure it. Using your example, how would you have structured it? where would you have placed things

Sep
09
4 years ago
Activity icon

Replied to I Keep Getting This Error In_array() Expects Parameter 2 To Be Array, Null Given

@luoshiben this doesn't work and you are right about the globals. But I'm following a tutorial on web scraping using php. Maybe you could provide some info. I'm trying to scrape data using laravel 5. I want to scrape data and store it in a database. know where I could see a tutorial on that? I want to do something like huffpost no more like techmeme but with different content

Activity icon

Started a new conversation I Keep Getting This Error In_array() Expects Parameter 2 To Be Array, Null Given

I keep getting this error

I keep getting this error in_array() expects parameter 2 to be array, null given

   get('pro', function(){

    $to_crawl = "http://bestspace.co";
    $c = array();

    function get_links($url)
    {
        global $c;
        $input = @file_get_contents($url);
        $regexp = '<a\s[^>]*href=(\"??)([^" >]*?)\\1[^>]*>(.*)<\/a>';
        preg_match_all("/$regexp/siU", $input, $matches);
        $base_url = parse_url($url, PHP_URL_HOST);

        $l = $matches[2];

        foreach($l as $link)
        {



            if (strpos($link, "#"))
            {
                $link = substr($link, 0, strpos($link, "#"));
            }

            if (substr($link,0,1) == ".")
            {
                $link = substr($link, 1);
            }

            if (substr($link, 0, 7) == "http://")
            {
                $link = $link;
            }

            else if (substr($link, 0, 8) == "https://")
            {
                $link = $link;
            }

            else if (substr($link, 0, 2) == "//")
            {
                $link = substr($link, 2);
            }

            else if (substr($link, 0, 2) == "#")
            {
                $link = $url;
            }

            else if (substr($link, 0, 7) == "mailto:")
            {
                $link = "[". $link."]";
            }

            else
            {
                if (substr($link, 0, 1) != "/")
                {
                    $link = $base_url."/".$link;
                }

                else
                {
                    $link = $base_url.$link;
                }
            }


            if (substr($link, 0, 7) != "http://" && substr($link, 0, 8) != "https://" && substr($link, 0, 1) != "[")
            {
                if (substr($url, 0, 8) == "https://")
                {
                    // prepend https
                    $link = "https://".$link;
                }
                else
                {
                    // prepend http
                    $link = "http://".$link;
                }
            }



            //echo $link."<br>";
            if (!in_array($link, $c))
            {
                array_push($c, $link);
            }
        }

    }

    get_links($to_crawl);

    foreach ($c as $page)
    {
        echo $page."<br>";
    }
});

I'm following a web scraping tutorial. but it does'nt work. also I'm using php storm ide, and usually I can command click on the functions, but It wont work for

        array()

for some reason. I was wondering if that was the issue

Sep
08
4 years ago
Activity icon

Started a new conversation Any Body Know Any Aggregator Tutorials

Been looking for how to make a news aggregating site using laravel 5. Anyone have any suggestions on where to find tutorials on this or something I could adapt from. This is not easy to find. I want to create something like techmeme but with different content

Aug
28
4 years ago
Activity icon

Replied to How Do You Store Json In Mysql And How To Retrieve It And Dispaly It

@deringer thanks for your reply it wasn't till after ours of searching that I realized that laravel returns json. I don't think I was making myself clear to people or some one would would have just told me that laravel does that. I'm going to try your approach. And you answered my question the way I needed it to. I dont have to store json because laravel already does that for me. Theres no need to store json. Thanks for your response once again.

Aug
27
4 years ago
Activity icon

Replied to How Do You Store Json In Mysql And How To Retrieve It And Dispaly It

@bobbybouwmann @snapey that's just what I was asking I'm not sure how to store i.t maybe if I explain a lil more you could advise me better. My goal is to have a client enter their zip code. That data will be stored in a variable called "userZip". That variable will be placed at the end of a url like this:

accessURL = "http://search.ams.usda.gov/farmersmarkets/v1/data.svc/zipSearch?zip=" + userZip;

which will return something like the following

{
"results": [
{
"id": "1010284",
"marketname": "1.8 175th Street Greenmarket"
},
{
"id": "1006142",
"marketname": "1.8 Hunts Point Farmers Market Saturday"
},
{
"id": "1009769",
"marketname": "1.8 Hunts Point Farmers Market Wednesday"
},
{
"id": "1006205",
"marketname": "1.9 Mount Eden Farmer's Market"
}
]
}

this information will then be used to populate a google map.

I want to store the json so I dont have to make individual api files for each result. I figured this is how it's done, so the results could be served dynamicall. I could be wrong. That's why I'm asking how it should be done. I'm assuming people store the jason in the database and return the proper results based off of that query. currently I have my controller setup like so:

<?php

namespace App\Http\Controllers;

use App\Post;
use App\Http\Requests;

class ApiController extends Controller
{
    public function index() {
        $results = [];

        foreach (Post::all() as $post)
        {
            $results[] = [
                'id' => $post->id,
                'marketname' => $post->subtitle,
            ];
        }

        return ['results' => $results];
    }
}

but it's not dynamic

Activity icon

Started a new conversation How Do You Store Json In Mysql And How To Retrieve It And Dispaly It

How do you store json in mysql and how to retrieve it and dispaly, for dynamic api purposes

Activity icon

Started a new conversation How To Dynamically Return Api Json From The Databse And How To Store Json In Mysql In Laravel 5.1

I am currently developing an api for my site to work with google maps. I have successfully developed an api with help from the community. But it only outputs a single page. I need it to be dynamic, because results will be based off of input from the user. As it stands my controller looks like this

 <?php

namespace App\Http\Controllers;

use App\Post;
use App\Http\Requests;

class ApiController extends Controller
{
    public function index() {
        $results = [];

        foreach (Post::all() as $post)
        {
            $results[] = [
                'id' => $post->id,
                'marketname' => $post->subtitle,
            ];
        }

        return ['results' => $results];
    }
}

but this isn't dynamic.

I was thinking of copying my search and modifying it. it looks like this

<?php

namespace App\Http\Controllers;

use App\Jobs\TagIndexData;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Post;
use App\Video;
use App\Tag;
use App\Http\Controllers\Controller;

class TagController extends Controller
{
    public function index(Request $request)
    {
        $query = $request->get('q');

        $posts = Post::where('title', 'LIKE', "%{$query}%")
                ->orwhere('subtitle', 'LIKE', "%{$query}%")->get();

        $videos = Video::where('title', 'LIKE', "%{$query}%")
            ->orwhere('subtitle', 'LIKE', "%{$query}%")->get();

            $tag = $request->get('tag');
            $data = $this->dispatch(new TagIndexData($tag));
            $layout = $tag ? Tag::layout($tag) : 'tags.layouts.index';

            return view($layout, $data)->withPosts($posts)->withVideos($videos);

    }
}

But I don't understand how to store json in mysql nor how to query it and output it Any help would be greatly appreciated.

To be clear on what I want. I want a person to enter their zipcode or address and then return a google map populated with markers indicating nearby events.

I am trying to modify a tutorial I did using a farmers market api mashed up with googles. Part of the javascript looks like this

 accessURL="http://search.ams.usda.gov/farmersmarkets/v1/data.svc/zipSearch?zip=" + userZip/address;

where userZip/address is input that I want to use to populate the google map

any advice on how I should structure this is welcomed

Activity icon

Replied to Whats's The Proper Way To Loop Through An Array For An Api In Laravel 5.1

Thank you too @markRedeman. Truly a kilobyte and one way to skin a cat. A lil programming humor

Activity icon

Replied to Whats's The Proper Way To Loop Through An Array For An Api In Laravel 5.1

@thomaskim Wow thanks that works like a charm and is definitely less verbose

Activity icon

Started a new conversation Whats's The Proper Way To Loop Through An Array For An Api In Laravel 5.1

Hello fellow programmers I am trying to loop through an array. I have experimented a bit but it's not working properly. it outputs.but it doesn't loop through everything I have in my database. this is my code for my ApiController

<?php

namespace App\Http\Controllers;

use App\Post;
use App\Http\Requests;

class ApiController extends Controller
{
    public function index()
    {
        foreach (Post::all() as $post )

        return array(
            'results' => [
                array('id' =>$post->title,
                    'marketname' => $post->subtitle),
             
            ]
        );
    }
}

also the curly bracket just before last is highlighted in my editor. When I hover over it, it says it's expecting a return. But if I move the return to where it says it should be, I get no output. To be clear I want to display something like this

"results": [
{
"id": "1002336",
"marketname": "0.2 Harvest Home Echo Park Market"
},
{
"id": "1006207",
"marketname": "0.3 Echo Park Market"
},
{
"id": "1003343",
"marketname": "0.4 La Familia Verde Farmers Market"
},

any help would be greatly appreciated

Aug
18
4 years ago
Activity icon

Replied to Elasticsearch Or Solr With Laravel?

@simber how much is elasticsearch?

Activity icon

Started a new conversation How Much Is Elasticsearch

I can't for the life of me find the price of elastic search nor can I find out if its free. people keep suggesting it but I don't know what's the cost

Activity icon

Replied to All Of A Sudden I'm Getting "SQLSTATE[HY000]: General Error: 2031" Error

@jimmck they weren't related. The columns were

    Post::search('%'.$query.'%', ['title', 'subtitle', 'content_raw', 'tags.title'])->paginate(15)
    Video::search('%'.$query.'%', ['title', 'subtitle', 'content_raw', 'tags.title'])->paginate(15)

the author of the package has just posted above this that 5.1 has broken his package and he won't be able to fix it

Aug
17
4 years ago
Activity icon

Replied to All Of A Sudden I'm Getting "SQLSTATE[HY000]: General Error: 2031" Error

@jimmck It was working. the purpose of my search was to search certain columns in my post and certain columns in my video table and return the results on my search page. nothing major. Originally I was trying to figure out how to do it. People made me feel like I asked how do I design a planet. All I wanted was a way to do a site search. I was advised by the guy who created Eloquence to use it. It worked perfectly and was easy to implement. But now it's giving me that error message. It's nothing I did. I have 20 different back ups each representing a stage towards my sites completion. They aren't working. I was just getting ready to deploy this site. Now I have to figure out how to implement a full site search. People don't know how to do it and the info is hard to find. I'll give what you guys recommended a try. how are people searching multiple tables in a database using a search field ont their site? this is beginning to seem almost esoteric

Activity icon

Replied to All Of A Sudden I'm Getting "SQLSTATE[HY000]: General Error: 2031" Error

This is why I don't like to use packages and would rather figure out how to do the code my own way, even if it takes longer. When Packages break nobody knows anything. A t least if i made it I'd know how to proceed. Could anybody recommend how I could search multiple columns in a table WITHOUT USING a package

Activity icon

Replied to All Of A Sudden I'm Getting "SQLSTATE[HY000]: General Error: 2031" Error

this is my tag controller file

<?php

namespace App\Http\Controllers;

use App\Jobs\TagIndexData;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Post;
use App\Video;
use App\Tag;
use App\Http\Controllers\Controller;

class TagController extends Controller
{
    public function index(Request $request)
    {
         $query = $request->get('q');

            $posts = $query
                ? Post::search('%'.$query.'%', ['title', 'subtitle', 'content_raw', 'tags.title'])->paginate(15)
                : Post::orderBy('published_at', 'desc')->paginate(15);

            $videos = $query
                ? Video::search('%'.$query.'%', ['title', 'subtitle', 'content_raw'])->paginate(15)
                : Video::orderBy('published_at', 'desc')->paginate(15);

            $tag = $request->get('tag');
            $data = $this->dispatch(new TagIndexData($tag));
            $layout = $tag ? Tag::layout($tag) : 'tags.layouts.index';

            return view($layout, $data)->withPosts($posts)->withVideos($videos); //->withVideos($videos);

    }
}

I am using

       sofa/eloquence": "~5.1@dev" 

to do my searches

Activity icon

Replied to All Of A Sudden I'm Getting "SQLSTATE[HY000]: General Error: 2031" Error

@willvincent @jimmck @helmerdavila The funny thing is I haven't touched anything and its been working. Just got in and I will try all the advice you guys mentioned

Activity icon

Started a new conversation All Of A Sudden I'm Getting "SQLSTATE[HY000]: General Error: 2031" Error

all of a sudden when I'm a few days away from deploying my site, I tried to just search around my site using the search field and out of the blue I get this error

QueryException in Connection.php line 636:
SQLSTATE[HY000]: General error: 2031 (SQL: select count(*) as aggregate     from (select `posts`.*, max(case when `posts`.`title` = ? then 15 else 0 end + case when `posts`.`title` like ? then 5 else 0 end + case when `posts`.`title` like ? then 1 else 0 end + case when `posts`.`subtitle` = ? then 15 else 0 end + case when `posts`.`subtitle` like ? then 5 else 0 end + case when `posts`.`subtitle` like ? then 1 else 0 end + case when `posts`.`content_raw` = ? then 15 else 0 end + case when `posts`.`content_raw` like ? then 5 else 0 end + case when `posts`.`content_raw` like ? then 1 else 0 end + case when `tags`.`title` = ? then 15 else 0 end + case when `tags`.`title` like ? then 5 else 0 end + case when `tags`.`title` like ? then 1 else 0 end) as relevance from `posts` left join `taggables` on `taggables`.`taggable_id` = `posts`.`id` left join `tags` on `taggables`.`tag_id` = `tags`.`id` where (`posts`.`title` like ? or `posts`.`subtitle` like ? or `posts`.`content_raw` like ? or `tags`.`title` like ?) group by `posts`.`id`) as `posts` where `relevance` >= 1)

The search was working fine just a couple of days ago. I have made NO changes to my controller or anything. So this is really confusing

Activity icon

Started a new conversation Is Laravel Haveing A Problem With My Css Scrolling Class?

I am trying to use a horizantal scroll on my home page and it's not working correctly. I am also using bootstrap. But I don't think that's whats causing the issue. Instead of scrolling it looks like it's stacked on top of each other.

heres my code in the view

@section('content')
<div class="container">
    <div class="row">
        <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">


            {{-- The Posts ------------------------------------------------------------------}}


            <div style="background-color:red"><h1>News</h1></div>
            @if ($posts->count())

            <div class="scroll">
                @foreach ($posts as $post)
                    <div class="post-preview" id="box">
                        <a href="{{ $post->url($tag) }}">
                            <h2 class="post-title">{{ $post->title }}</h2>
                            @if ($post->subtitle)
                                <h3 class="post-subtitle">{{ $post->subtitle }}</h3>
                            @endif
                        </a>
                        <p class="post-meta">
                            Posted on {{ $post->published_at->format('F j, Y') }}
                            @if ($post->tags->count())
                                in
                                {!! join(', ', $post->tagLinks()) !!}
                            @endif
                        </p>
                        <hr>
                    </div>
                @endforeach

            @else
                <h1 style="text-align: center">no posts match your search</h1>
            @endif
        </div>

            {{-- End Posts ------------------------------------------------------------------}}





            {{-- The Videos --}}
            <div style="background-color:red"><h1>Videos</h1></div>
            @if ($videos->count())

                <!--<h2>{{ ($videos->count()) }} Articles</h2>  displays count-->

                @foreach ($videos as $video)
                    <div class="post-preview">
                        <a href="{{ $video->url($tag) }}">
                            <h2 class="post-title">{{ $video->title }}</h2>
                            @if ($video->subtitle)
                                <h3 class="post-subtitle">{{ str_limit($video->subtitle, 20) }}</h3>
                            @endif
                        </a>
                        <p class="post-meta">
                            Posted on {{ $video->published_at->format('F j, Y') }}
                            @if ($video->tags->count())
                                in
                                {!! join(', ', $video->tagLinks()) !!}
                            @endif
                        </p>
                    </div>
                    <hr>
                @endforeach

            @else
                <h1 style="text-align: center">no videos match your search</h1>
            @endif
            {{-- End videos --}}



            {{--  {!! $videos->render() !!} --}}

            {{-- The Pager --}}

        </div>

    </div>
</div>
@stop

and heres the css:

#box {
    width: 243px;
    height: 100%;
    margin: 0 4px 5px 0;
    padding:0;
    border-style: solid;
    border-width: 1px;
    /* border-radius: 10px; */
    display: inline-block;

}


.scroll {
    width: 100%;
    padding: 10px 0;
    height: 202px;
    overflow-x: auto;
    overflow-y: hidden;
    /* border: 1px solid; */
    white-space: nowrap;
}

any help with this will be appreciated. I've used this code in another site and it worked

Aug
12
4 years ago
Activity icon

Replied to How Do I Store Data In A Variable Using A Form?

@pmall thank. Following your advice. it seems to be the most logical

Activity icon

Replied to How Do I Store Data In A Variable Using A Form?

@pmall This is the best way? I thought there was a way to do it like that.But I guess what your saying does kinda make sense

Activity icon

Started a new conversation How Do I Store Data In A Variable Using A Form?

I am following a tutorial called l5beauty by Chuck Heitzman. I want to modify his code. The way it's set up now, the image is set in a config file like this

    'page_image' => 'home-bg.jpg',

and is returned in my HomeIndexdata class like so:

protected function normalIndexData()
{
    $posts = Post::with('tags')
        ->where('published_at', '<=', Carbon::now())
        ->where('is_draft', 0)
        ->orderBy('published_at', 'desc')
        ->simplePaginate(config('blog.posts_per_page'));

    $videos = Video::with('tags')
        ->where('published_at', '<=', Carbon::now())
        ->where('is_draft', 0)
        ->orderBy('published_at', 'desc')
        ->simplePaginate(config('blog.posts_per_page'));

    return [
        'title' => config('home.title'),
        'subtitle' => config('home.subtitle'),
        'posts' => $posts,
        'videos' => $videos,
        'page_image' => config('home.page_image'),
        'meta_description' => config('home.description'),
        'reverse_direction' => false,
        'tag' => null,
    ];
}

i want to be able to change the image in my admin area. So when an event or holiday comes up I can change the image to a christmas tree or a rabbit for easter etc. How would I implement this. Do I use apc_store and apc_fetch or is there a simpler laravel way to do this

Aug
09
4 years ago
Activity icon

Started a new conversation How Can I Make My Video Tags And Blog Tags Return On The Same Page

I'm trying to get my video tags and article tags to return on the same page. I've modified a tutorial I was following that only had blog posts and Ive included videos. But I'm not sure how to make the videos and articles that share a tag, return on the same page. I feel like the following code is what I need to alter some how

from my blog model:

public function url(Tag $tag = null)
    {
        $url = url('blog/'.$this->slug);
        if ($tag) {
            $url .= '?tag='.urlencode($tag->tag);
        }

        return $url;
    }

public function tagLinks($base = '/blog?tag=%TAG%')
    {
        $tags = $this->tags()->lists('tag');
        $return = [];
        foreach ($tags as $tag) {
            $url = str_replace('%TAG%', urlencode($tag), $base);
            $return[] = '<a href="'.$url.'">'.e($tag).'</a>';
        }
        return $return;
    }

from my video model:

public function url(Tag $tag = null)
    {
        $url = url('video/'.$this->slug);  // this fixed my problem it was 'blog/'
        if ($tag) {
            $url .= '?tag='.urlencode($tag->tag);
        }
        return $url;
    }


public function tagLinks($base = '/video?tag=%TAG%') // this fixed my problem        it was 'blog?tag=%TAG%/'
    {
        $tags = $this->tags()->lists('tag');
        $return = [];
     foreach ($tags as $tag) {
            $url = str_replace('%TAG%', urlencode($tag), $base);
            $return[] = '<a href="'.$url.'">'.e($tag).'</a>';
        }
        return $return;
    }

am I supposed to create a separate controller to make this work?

Aug
08
4 years ago
Activity icon

Started a new conversation Should Videos And Articles Be In The Same Table?

I am asking this because i currently have articles with its own controller, views, migration etc and the exact same for videos. But It feels like Thats not how the pros are doing it. I want my project to have a polished professional feel. But I haven't seen anything to guide me in my sites architecture. All the tutorials I've seen are for blogs that simply display text articles not videos.

My question is should I put videos and articles in the same table and just have column called "type" for instance where I would either but video or article in it. For one I think it would be easier for searching my whole site and displaying the results. Right now I have on the splash page a section for articles and below it a section for videos and it just doesnt feel cohesive. I just want to know what are some peoples take on this. How would a pro structure their site.

I'm actually leaning toward putting articles and videos in the same table and just screening my search's by the column called "type" querying all posts where type is article or video. I'd like some advice though thanks

Aug
06
4 years ago
Activity icon

Replied to How Can I Dynamically Load Embedded Videos From Youtube Using Jwplayer And Laravel 5.1?

I figured it out. After I listened to your advice about removeing the quotest, I had to remove the only the function it's parentesis and curly brackets. Then everything worked

Activity icon

Replied to How Can I Dynamically Load Embedded Videos From Youtube Using Jwplayer And Laravel 5.1?

@IBJNewMedia yes. thats where the URL is stored. I removed the quotation marks but it still doesn't work

Activity icon

Started a new conversation How Can I Dynamically Load Embedded Videos From Youtube Using Jwplayer And Laravel 5.1?

I am using the laravel framework and I am trying to use JwPlayer to load the videos dynamically. I tried to do this

    <script type="text/javascript" src="http://content.jwplatform.com/libraries/WQWJdvRx.js"></script>

    <div id="myElement" title="{{ $video->subtitle }}"></div>
    <script>

function myFunction(){
    var div1 = document.getElementById("myElement");
    var attr = div1.getAttribute("title");


    jwplayer("myElement").setup({

        file: "attr",
        width: 640,
        height: 360,
        title:"title goes here",
        stretching:"fill",
        skin:{
            name:"stormtrooper"
        }
    });
}

I tried using javascript to get the class name which is actually specific to a video. the variable attr then I tried using attr variable as my file path. But it's not working. Any Help would be appreciated

Jul
28
4 years ago
Activity icon

Started a new conversation I Keep Getting This Error SQLSTATE[23000]: Integrity Constraint Violation: 1062 Duplicate Entry '' For Key 'videos_slug_unique'

I have a site I created that has a blog section and a video section. I had a config file for blog that I tried to share with the video section but it wasn't working properly so I created a separate config for video. and modified my column names for video from

    $title and $subtitle 

to

    $v_title and $v_subtitle. 

but when I do I get the following error

    SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key 'videos_slug_unique'

for some reason a slug is not being produced and this causes the issue. The slug is unique in my table. If I change the variables to how they were

    $title and $subtitle 

it works, why is that?

this is my Admin videoController

    <?php
        
        namespace App\Http\Controllers\Admin;
        
        use App\Jobs\VideoFormFields;
        use App\Http\Requests;
        use App\Http\Requests\VideoCreateRequest;
        use App\Http\Requests\VideoUpdateRequest;
        use App\Http\Controllers\Controller;
        use App\Video;
        
        class VideoController extends Controller
        {
            /**
             * Display a listing of the posts.
             */
            public function index()
            {
                return view('admin.video.index')
                    ->withVideos(Video::all());
            }
        
            /**
             * Show the new video form
             */
            public function create()
            {
                $data = $this->dispatch(new VideoFormFields());
        
                return view('admin.video.create', $data);
            }
        
            /**
             * Store a newly created Video
             *
             * @param VideoCreateRequest $request
             */
            public function store(VideoCreateRequest $request)
            {
                $video = Video::create($request->videoFillData());
                $video->syncTags($request->get('tags', []));
        
                return redirect()
                    ->route('admin.video.index')
                    ->withSuccess('New Video Successfully Created.');
            }
        
            /**
             * Show the video edit form
             *
             * @param  int  $id
             * @return Response
             */
            public function edit($id)
            {
                $data = $this->dispatch(new VideoFormFields($id));
        
                return view('admin.video.edit', $data);
            }
        
            /**
             * Update the Video
             *
             * @param VideoUpdateRequest $request
             * @param int  $id
             */
            public function update(VideoUpdateRequest $request, $id)
            {
                $video = Video::findOrFail($id);
                $video->fill($request->videoFillData());
                $video->save();
                $video->syncTags($request->get('tags', []));
        
                if ($request->action === 'continue') {
                    return redirect()
                        ->back()
                        ->withSuccess('Video saved.');
                }
        
                return redirect()
                    ->route('admin.video.index')
                    ->withSuccess('Video saved.');
            }
        
            /**
             * Remove the specified resource from storage.
             *
             * @param  int  $id
             * @return Response
             */
            public function destroy($id)
            {
                $video = Video::findOrFail($id);
                $video->tags()->detach();
                $video->delete();
        
                return redirect()
                    ->route('admin.video.index')
                    ->withSuccess('Video deleted.');
            }
        }

this is my videoFormFields

    <?php
            
            namespace App\Jobs;
            
            use App\Video;
            use App\Tag;
            use Carbon\Carbon;
            use Illuminate\Contracts\Bus\SelfHandling;
            
            class VideoFormFields extends Job implements SelfHandling
            {
                /**
                 * The id (if any) of the Post row
                 *
                 * @var integer
                 */
                protected $id;
            
                /**
                 * List of fields and default value for each field
                 *
                 * @var array
                 */
                protected $fieldList = [
                    'v_title' => '',
                    'v_subtitle' => '',
                    'page_image' => '',
                    'content' => '',
                    'meta_description' => '',
                    'is_draft' => "0",
                    'publish_date' => '',
                    'publish_time' => '',
                    'layout' => 'video.layouts.v_post',
                    'tags' => [],
                ];
            
                /**
                 * Create a new command instance.
                 *
                 * @param integer $id
                 */
                public function __construct($id = null)
                {
                    $this->id = $id;
                }
            
                /**
                 * Execute the command.
                 *
                 * @return array of fieldnames => values
                 */
                public function handle()
                {
                    $fields = $this->fieldList;
            
                    if ($this->id) {
                        $fields = $this->fieldsFromModel($this->id, $fields);
                    } else {
                        $when = Carbon::now()->addHour();
                        $fields['publish_date'] = $when->format('M-j-Y');
                        $fields['publish_time'] = $when->format('g:i A');
                    }
            
                    foreach ($fields as $fieldName => $fieldValue) {
                        $fields[$fieldName] = old($fieldName, $fieldValue);
                    }
            
                    return array_merge(
                        $fields,
                        ['allTags' => Tag::lists('tag')->all()]
                    );
                }
            
                /**
                 * Return the field values from the model
                 *
                 * @param integer $id
                 * @param array $fields
                 * @return array
                 */
                protected function fieldsFromModel($id, array $fields)
                {
                    $video = Video::findOrFail($id);
            
                    $fieldNames = array_keys(array_except($fields, ['tags']));
            
                    $fields = ['id' => $id];
                    foreach ($fieldNames as $field) {
                        $fields[$field] = $video->{$field};
                    }
            
                    $fields['tags'] = $video->tags()->lists('tag')->all();
            
                    return $fields;
                }
            }

this is my videoCreateRequest

    <?php
            
            namespace App\Http\Requests;
            
            use Carbon\Carbon;
            
            class VideoCreateRequest extends Request
            {
                /**
                 * Determine if the user is authorized to make this request.
                 */
                public function authorize()
                {
                    return true;
                }
            
                /**
                 * Get the validation rules that apply to the request.
                 *
                 * @return array
                 */
                public function rules()
                {
                    return [
                        'v_title' => 'required',
                        'v_subtitle' => 'required',
                        'content_raw' => 'required', //                                         HERE CHANGED
                        'publish_date' => 'required',
                        'publish_time' => 'required',
                        'layout' => 'required',
                    ];
                }
            
                /**
                 * Return the fields and values to create a new VIDEO post from
                 */
                public function videoFillData()
                {
                    $published_at = new Carbon(
                        $this->publish_date.' '.$this->publish_time
                    );
                    return [
                        'v_title' => $this->v_title,
                        'v_subtitle' => $this->v_subtitle,
                        'page_image' => $this->page_image,
                        'content_raw' => $this->content_raw, //                                  HERE CHANGED
                        'meta_description' => $this->meta_description,
                        'is_draft' => (bool)$this->is_draft,
                        'published_at' => $published_at,
                        'layout' => $this->layout,
                    ];
                }
            }

this is my videoUpdateRequest <?php namespace App\Http\Requests;

            class VideoUpdateRequest extends VideoCreateRequest
            {
                //
            }

this is my video model

    <?php
            
            namespace App;
            
            use App\Services\Markdowner;
            use Illuminate\Database\Eloquent\Model;
            use Carbon\Carbon;
            use Sofa\Eloquence\Eloquence;
            class Video extends Model
            {
                use Eloquence;
            
                protected $dates = ['published_at'];
            
                protected $fillable = [
                    'v_title', 'v_subtitle', 'content_raw', 'page_image', 'meta_description',
                    'layout', 'is_draft', 'published_at',
                ];
            
                /**
                 * The many-to-many relationship between posts and tags.
                 *
                 * @return BelongsToMany
                 */
                public function tags()
                {
                    return $this->morphToMany('App\Tag', 'taggable');
                }
            
                /**
                 * Set the title attribute and automatically the slug
                 *
                 * @param string $value
                 */
                public function setTitleAttribute($value)
                {
                    $this->attributes['title'] = $value;
            
                    if (! $this->exists) {
                        $this->setUniqueSlug($value, '');
                    }
                }
            
                /**
                 * Recursive routine to set a unique slug
                 *
                 * @param string $title
                 * @param mixed $extra
                 */
                protected function setUniqueSlug($title, $extra)
                {
                    $slug = str_slug($title.'-'.$extra);
            
                    if (static::whereSlug($slug)->exists()) {
                        $this->setUniqueSlug($title, $extra + 1);
                        return;
                    }
            
                    $this->attributes['slug'] = $slug;
                }
            
                /**
                 * Set the HTML content automatically when the raw content is set
                 *
                 * @param string $value
                 */
                public function setContentRawAttribute($value)
                {
                    $markdown = new Markdowner();
            
                    $this->attributes['content_raw'] = $value;
                    $this->attributes['content_html'] = $markdown->toHTML($value);
                }
            
                /**
                 * Sync tag relation adding new tags as needed
                 *
                 * @param array $tags
                 */
                public function syncTags(array $tags)
                {
                    Tag::addNeededTags($tags);
            
                    if (count($tags)) {
                        $this->tags()->sync(
                            Tag::whereIn('tag', $tags)->lists('id')->all()
                        );
                        return;
                    }
            
                    $this->tags()->detach();
                }
            
                /**
                 * Return the date portion of published_at
                 */
                public function getPublishDateAttribute($value)
                {
                    return $this->published_at->format('M-j-Y');
                }
            
                /**
                 * Return the time portion of published_at
                 */
                public function getPublishTimeAttribute($value)
                {
                    return $this->published_at->format('g:i A');
                }
            
                /**
                 * Alias for content_raw
                 */
                public function getContentAttribute($value)
                {
                    return $this->content_raw;
                }
            
                /**
                 * Return URL to post
                 *
                 * @param Tag $tag
                 * @return string
                 */
                public function url(Tag $tag = null)
                {
                    $url = url('video/'.$this->slug);  // this fixed my problem it was 'blog/'
                    if ($tag) {
                        $url .= '?tag='.urlencode($tag->tag);
                    }
            
                    return $url;
                }
            
                /**
                 * Return array of tag links
                 *
                 * @param string $base
                 * @return array
                 */
                public function tagLinks($base = '/video?tag=%TAG%') // this fixed my problem it was 'blog?tag=%TAG%/'
                {
                    $tags = $this->tags()->lists('tag');
                    $return = [];
                    foreach ($tags as $tag) {
                        $url = str_replace('%TAG%', urlencode($tag), $base);
                        $return[] = '<a href="'.$url.'">'.e($tag).'</a>';
                    }
                    return $return;
                }
            
                /**
                 * Return next post after this one or null
                 *
                 * @param Tag $tag
                 * @return Post
                 */
                public function newerPost(Tag $tag = null)  //                 //here newVideo v_index & v_post
                {
                    $query =
                        static::where('published_at', '>', $this->published_at)
                            ->where('published_at', '<=', Carbon::now())
                            ->where('is_draft', 0)
                            ->orderBy('published_at', 'asc');
                    if ($tag) {
                        $query = $query->whereHas('tags', function ($q) use ($tag) {
                            $q->where('tag', '=', $tag->tag);
                        });
                    }
            
                    return $query->first();
                }
            
                /**
                 * Return older post before this one or null
                 *
                 * @param Tag $tag
                 * @return Post
                 */
                public function olderPost(Tag $tag = null) //                 //here olderVideo v_index & v_post
                {
                    $query =
                        static::where('published_at', '<', $this->published_at)
                            ->where('is_draft', 0)
                            ->orderBy('published_at', 'desc');
                    if ($tag) {
                        $query = $query->whereHas('tags', function ($q) use ($tag) {
                            $q->where('tag', '=', $tag->tag);
                        });
                    }
            
                    return $query->first();
                }
            }

this is my video table

    <?php
        
        use Illuminate\Database\Schema\Blueprint;
        use Illuminate\Database\Migrations\Migration;
        
        class CreateVideosTable extends Migration
        {
            /**
             * Run the migrations.
             *
             * @return void
             */
            public function up()
            {
                Schema::create('videos', function (Blueprint $table) {
                    $table->increments('id');
                    $table->string('slug')->unique();
                    $table->string('v_title');
                    $table->string('v_subtitle');
                    $table->text('content_raw');
                    $table->text('content_html');
                    $table->string('page_image');
                    $table->string('meta_description');
                    $table->boolean('is_draft');
                    $table->string('layout')
                        ->default('blog.layouts.post');
                    $table->timestamps();
                    $table->timestamp('published_at')->index();
                });
            }
        
            /**
             * Reverse the migrations.
             */
            public function down()
            {
                Schema::drop('videos');
            }
        }
Jul
24
4 years ago
Activity icon

Started a new conversation My Config File Only Works On One Page

I have this in my blog.config file

        'name' => "search",
        'title' => 'SEARCH',
        'subtitle' => 'novid',
        'description' => 'This is my meta description',
        'author' => 'ime',
        'page_image' => 'home-bg.jpg',

I have this in my video.config file

    'name' => "video",
        'title' => 'video',
        'subtitle' => 'video',
        'description' => 'This is my video description',
        'author' => 'inedme',
        'page_image' => 'home-bg.jpg',

I have this in my blog.layouts.master $title or config('blog.title')

I have this in my video.layouts.master $title or config('video.title')

thing is only the blog.title value shows in the example above. do I have to make totally different variable names for my video variables for this to work properly?

Am I supposed to split my site by each nav link i.e. blog would have it's own controller and blog.config and video its own controller and video.config. I have only seen examples done with blogs that only have a blog section only. no videos page like I'm trying to do

Jul
20
4 years ago
Activity icon

Replied to How Can I Make It So My Search Controller Knows Whether My Video Controller Is Making A Query Or My Posts Controller Is Making A Query

@uxweb all the code you posted looks good but I'm going to try your last one because as you said it's cleaner and the most efficient. I'm going to copy and paste it all

Activity icon

Started a new conversation How Can I Make It So My Search Controller Knows Whether My Video Controller Is Making A Query Or My Posts Controller Is Making A Query

I have to views one is a post the other is video they each have their own nav-partial where I have a search field. This isn't practical because the action attribute must be the same for it to work. For example If I am in video and want to run a search the action must be

    action = "VideoController@index"

for it to work. This must also be the action in the Post nav-partial. So I figured I'd create a search controller so the action in either post or video would be

    action = "SearchController@index"

but how do I write the code to make it so my SearchController knows if the action is coming from the post view nav-partial or the video view nav-parial?

Jul
19
4 years ago
Activity icon

Replied to My Search And Tags Not Working Because Of My Structure

no that's not the issue. I dont get error messages. The search and the tags dont return what I'm querrying

Activity icon

Started a new conversation My Search And Tags Not Working Because Of My Structure

My search not working because of my structure

my tags work like this

public function index(Request $request)
    {
        $tag = $request->get('tag');
        $data = $this->dispatch(new BlogIndexData($tag));
        $layout = $tag ? Tag::layout($tag) : 'blog.layouts.index';

        return view($layout, $data);
    }

but when I try to add search functionality like this

public function index(Request $request)
    {
        $query = $request->get('q');
        $posts = $query
            ? Post::search('%'.$query.'%', ['title', 'subtitle', 'content_raw', 'tags.title'])->paginate(15)
            : Post::orderBy('published_at', 'desc')->paginate(15);
        $videos = $query
            ? Video::search('%'.$query.'%', ['title', 'subtitle', 'content_raw'])->paginate(15)
            : Video::orderBy('published_at', 'desc')->paginate(15);
    
        $tag = $request->get('tag');
        $data = $this->dispatch(new BlogIndexData($tag));
        $layout = $tag ? Tag::layout($tag) : 'blog.layouts.index';

        return view($layout, $data)->withPosts($posts)->withVideos($videos);
    }

the tags don't work BUT the search does work. any suggestions?

Jul
18
4 years ago
Activity icon

Started a new conversation My Tag Search Won't Work

when I click on my tags, they no longer filter as they did before. and I dont know why. heres my BlogController

    <?php
    namespace App\Http\Controllers;

    use App\Jobs\BlogIndexData;
    use App\Http\Requests;
    use App\Post;
    use App\Tag;
    use App\Video;
    use Illuminate\Http\Request;
    use App\Services\RssFeed;
    use App\Services\SiteMap;

    class BlogController extends Controller
    {
     public function index(Request $request)
        {
        $query = $request->get('q');
        $posts = $query
            ? Post::search('%'.$query.'%', ['title', 'subtitle', 'content_raw', 'tags.title'])->paginate(15)
            : Post::orderBy('published_at', 'desc')->paginate(15);
        $videos = $query
            ? Video::search('%'.$query.'%', ['title', 'subtitle', 'content_raw'])->paginate(15)
            : Video::orderBy('published_at', 'desc')->paginate(15);


        $tag = $request->get('tag');
        $data = $this->dispatch(new BlogIndexData($tag));
        $layout = $tag ? Tag::layout($tag) : 'blog.layouts.index';



        return view($layout, $data)->withPosts($posts)->withVideos($videos);
    }

    public function showPost($slug, Request $request)
    {
        $post = Post::with('tags')->whereSlug($slug)->firstOrFail();
        $tag = $request->get('tag');
        if ($tag) {
            $tag = Tag::whereTag($tag)->firstOrFail();
        }

        return view($post->layout, compact('post', 'tag', 'slug'));
    }

    public function rss(RssFeed $feed)
    {
        $rss = $feed->getRSS();

        return response($rss)
            ->header('Content-type', 'application/rss+xml');
    }

    public function siteMap(SiteMap $siteMap)
    {
        $map = $siteMap->getSiteMap();

        return response($map)
            ->header('Content-type', 'text/xml');
    }

I don't know what is going on @otepas @jaewun @alenabdula @JarekTkaczyk do you know why that is?

Activity icon

Started a new conversation I Just Realized My Tag Search Isnt Working

when I click on my tags, they no longer filter as they did before. and I dont know why. heres my BlogController

<?php
namespace App\Http\Controllers;

use App\Jobs\BlogIndexData;
use App\Http\Requests;
use App\Post;
use App\Tag;
use App\Video;
use Illuminate\Http\Request;
use App\Services\RssFeed;
use App\Services\SiteMap;

class BlogController extends Controller
{
    public function index(Request $request)
    {
    $query = $request->get('q');
    $posts = $query
        ? Post::search('%'.$query.'%', ['title', 'subtitle', 'content_raw', 'tags.title'])->paginate(15)
        : Post::orderBy('published_at', 'desc')->paginate(15);
    $videos = $query
        ? Video::search('%'.$query.'%', ['title', 'subtitle', 'content_raw'])->paginate(15)
        : Video::orderBy('published_at', 'desc')->paginate(15);


    $tag = $request->get('tag');
    $data = $this->dispatch(new BlogIndexData($tag));
    $layout = $tag ? Tag::layout($tag) : 'blog.layouts.index';



    return view($layout, $data)->withPosts($posts)->withVideos($videos);
}

public function showPost($slug, Request $request)
{
    $post = Post::with('tags')->whereSlug($slug)->firstOrFail();
    $tag = $request->get('tag');
    if ($tag) {
        $tag = Tag::whereTag($tag)->firstOrFail();
    }

    return view($post->layout, compact('post', 'tag', 'slug'));
}

public function rss(RssFeed $feed)
{
    $rss = $feed->getRSS();

    return response($rss)
        ->header('Content-type', 'application/rss+xml');
}

public function siteMap(SiteMap $siteMap)
{
    $map = $siteMap->getSiteMap();

    return response($map)
        ->header('Content-type', 'text/xml');
}

I don't know what is going on

Jul
16
4 years ago
Activity icon

Started a new conversation Dont Know How To Delete Post

      dont know how to delete post
Jul
15
4 years ago
Activity icon

Started a new conversation I Keep Getting A Whoops! There Were Some Problems With Your Input. The Content Raw Field Is Required

I dont understand why I keep getting this error message

Whoops! There were some problems with your input. The content raw field is required

my VideoFormFields.php use App\Video; use App\Tag; use Carbon\Carbon; use Illuminate\Contracts\Bus\SelfHandling;

class VideoFormFields extends Job implements SelfHandling { /** * The id (if any) of the Post row * * @var integer */ protected $id;

/**
 * List of fields and default value for each field
 *
 * @var array
 */
protected $fieldList = [
    'title' => '',
    'subtitle' => '',
    'page_image' => '',
    'content_raw' => '',
    'meta_description' => '',
    'is_draft' => "0",
    'publish_date' => '',
    'publish_time' => '',
    'layout' => 'blog.layouts.post',
    'tags' => [],
];

/**
 * Create a new command instance.
 *
 * @param integer $id
 */
public function __construct($id = null)
{
    $this->id = $id;
}

/**
 * Execute the command.
 *
 * @return array of fieldnames => values
 */
public function handle()
{
    $fields = $this->fieldList;

    if ($this->id) {
        $fields = $this->fieldsFromModel($this->id, $fields);
    } else {
        $when = Carbon::now()->addHour();
        $fields['publish_date'] = $when->format('M-j-Y');
        $fields['publish_time'] = $when->format('g:i A');
    }

    foreach ($fields as $fieldName => $fieldValue) {
        $fields[$fieldName] = old($fieldName, $fieldValue);
    }

    return array_merge(
        $fields,
        ['allTags' => Tag::lists('tag')->all()]
    );
}

/**
 * Return the field values from the model
 *
 * @param integer $id
 * @param array $fields
 * @return array
 */
protected function fieldsFromModel($id, array $fields)
{
    $video = Video::findOrFail($id);

    $fieldNames = array_keys(array_except($fields, ['tags']));

    $fields = ['id' => $id];
    foreach ($fieldNames as $field) {
        $fields[$field] = $video->{$field};
    }

    $fields['tags'] = $video->tags()->lists('tag')->all();

    return $fields;
}

}

my Video.php model

use App\Services\Markdowner; use Illuminate\Database\Eloquent\Model; use Carbon\Carbon; use Sofa\Eloquence\Eloquence; class Video extends Model { use Eloquence;

protected $dates = ['published_at'];

protected $fillable = [
    'title', 'subtitle', 'content_raw', 'page_image', 'meta_description',
    'layout', 'is_draft', 'published_at',
];

public function tags()
{
    return $this->morphToMany('App\Tag', 'taggable');
}

public function setTitleAttribute($value)
{
    $this->attributes['title'] = $value;

    if (! $this->exists) {
        $this->attributes['slug'] = str_slug($value);
    }
}

/**
 * Recursive routine to set a unique slug
 *
 * @param string $title
 * @param mixed $extra
 */
protected function setUniqueSlug($title, $extra)
{
    $slug = str_slug($title.'-'.$extra);

    if (static::whereSlug($slug)->exists()) {
        $this->setUniqueSlug($title, $extra + 1);
        return;
    }

    $this->attributes['slug'] = $slug;
}

/**
 * Set the HTML content automatically when the raw content is set
 *
 * @param string $value
 */
public function setContentRawAttribute($value)
{
    $markdown = new Markdowner();

    $this->attributes['content_raw'] = $value;
    $this->attributes['content_html'] = $markdown->toHTML($value);
}

/**
 * Sync tag relation adding new tags as needed
 *
 * @param array $tags
 */
public function syncTags(array $tags)
{
    Tag::addNeededTags($tags);

    if (count($tags)) {
        $this->tags()->sync(
            Tag::whereIn('tag', $tags)->lists('id')->all()
        );
        return;
    }

    $this->tags()->detach();
}

/**
 * Return the date portion of published_at
 */
public function getPublishDateAttribute($value)
{
    return $this->published_at->format('M-j-Y');
}

/**
 * Return the time portion of published_at
 */
public function getPublishTimeAttribute($value)
{
    return $this->published_at->format('g:i A');
}

/**
 * Alias for content_raw
 */
public function getContentAttribute($value)
{
    return $this->content_raw;
}

/**
 * Return URL to post
 *
 * @param Tag $tag
 * @return string
 */
public function url(Tag $tag = null)
{
    $url = url('blog/'.$this->slug);
    if ($tag) {
        $url .= '?tag='.urlencode($tag->tag);
    }

    return $url;
}

/**
 * Return array of tag links
 *
 * @param string $base
 * @return array
 */
public function tagLinks($base = '/blog?tag=%TAG%')
{
    $tags = $this->tags()->lists('tag');
    $return = [];
    foreach ($tags as $tag) {
        $url = str_replace('%TAG%', urlencode($tag), $base);
        $return[] = '<a href="'.$url.'">'.e($tag).'</a>';
    }
    return $return;
}

/**
 * Return next post after this one or null
 *
 * @param Tag $tag
 * @return Post
 */
public function newerPost(Tag $tag = null)
{
    $query =
        static::where('published_at', '>', $this->published_at)
            ->where('published_at', '<=', Carbon::now())
            ->where('is_draft', 0)
            ->orderBy('published_at', 'asc');
    if ($tag) {
        $query = $query->whereHas('tags', function ($q) use ($tag) {
            $q->where('tag', '=', $tag->tag);
        });
    }

    return $query->first();
}

/**
 * Return older post before this one or null
 *
 * @param Tag $tag
 * @return Post
 */
public function olderPost(Tag $tag = null)
{
    $query =
        static::where('published_at', '<', $this->published_at)
            ->where('is_draft', 0)
            ->orderBy('published_at', 'desc');
    if ($tag) {
        $query = $query->whereHas('tags', function ($q) use ($tag) {
            $q->where('tag', '=', $tag->tag);
        });
    }

    return $query->first();
}

}


my VideoController.php

use App\Jobs\VideoFormFields; use App\Http\Requests; use App\Http\Requests\VideoCreateRequest; use App\Http\Requests\VideoUpdateRequest; use App\Http\Controllers\Controller; use App\Video;

class VideoController extends Controller { /** * Display a listing of the posts. * */ public function index() { return view('admin.video.index') ->withVideos(Video::all()); }

/**
 * Show the new video form
 */
public function create()
{
    $data = $this->dispatch(new VideoFormFields());

    return view('admin.video.create', $data);
}

/**
 * Store a newly created Video
 *
 * @param VideoCreateRequest $request
 */
public function store(VideoCreateRequest $request)
{
    $video = Video::create($request->videoFillData());
    $video->syncTags($request->get('tags', []));

    return redirect()
        ->route('admin.video.index')
        ->withSuccess('New Video Successfully Created.');
}

/**
 * Display the specified resource.
 *
 * @param  int  $id
 * @return Response
 */
public function show($id)
{
    //
}

/**
 * Show the video edit form
 *
 * @param  int  $id
 * @return Response
 */
public function edit($id)
{
    $data = $this->dispatch(new VideoFormFields($id));

    return view('admin.video.edit', $data);
}

/**
 * Update the Video
 *
 * @param VideoUpdateRequest $request
 * @param int  $id
 */
public function update(VideoUpdateRequest $request, $id)
{
    $video = Video::findOrFail($id);
    $video->fill($request->videoFillData());
    $video->save();
    $video->syncTags($request->get('tags', []));

    if ($request->action === 'continue') {
        return redirect()
            ->back()
            ->withSuccess('Video saved.');
    }

    return redirect()
        ->route('admin.video.index')
        ->withSuccess('Video saved.');
}

/**
 * Remove the specified resource from storage.
 *
 * @param  int  $id
 * @return Response
 */
public function destroy($id)
{
    $video = Video::findOrFail($id);
    $video->tags()->detach();
    $video->delete();

    return redirect()
        ->route('admin.video.index')
        ->withSuccess('Video deleted.');
}

}

my videocreaterequest.php

use Carbon\Carbon;

class VideoCreateRequest extends Request { /** * Determine if the user is authorized to make this request. */ public function authorize() { return true; }

/**
 * Get the validation rules that apply to the request.
 *
 * @return array
 */
public function rules()
{
    return [
        'title' => 'required',
        'subtitle' => 'required',
        'content_raw' => 'required', //                                         HERE CHANGED
        'publish_date' => 'required',
        'publish_time' => 'required',
        'layout' => 'required',
    ];
}

/**
 * Return the fields and values to create a new VIDEO post from
 */
public function videoFillData()
{
    $published_at = new Carbon(
        $this->publish_date.' '.$this->publish_time
    );
    return [
        'title' => $this->title,
        'subtitle' => $this->subtitle,
        'page_image' => $this->page_image,
        'content_raw' => $this->content_raw, //                                  HERE CHANGED
        'meta_description' => $this->meta_description,
        'is_draft' => (bool)$this->is_draft,
        'published_at' => $published_at,
        'layout' => $this->layout,
    ];
}

}

my 2015_07_235729_create_videos_table.php

use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration;

class CreateVideosTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('videos', function (Blueprint $table) { $table->increments('id'); $table->string('slug')->unique(); $table->string('title'); $table->string('subtitle'); $table->text('content_raw'); $table->text('content_html'); $table->string('page_image'); $table->string('meta_description'); $table->boolean('is_draft'); $table->string('layout') ->default('blog.layouts.post'); $table->timestamps(); $table->timestamp('published_at')->index(); }); }

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::drop('videos');
}

}

I used this for my posts but for this it's not working