Sidirgot

Hire Me

Experience

30,330

0 Best Reply Awards

  • Member Since 1 Year Ago
  • 289 Lessons Completed
  • 0 Favorites

10th July, 2018

Sidirgot left a reply on Display Comment Replies For The Specific Comment • 2 months ago

Found the solution after a good long sleep!

In the v-for loop for the replies i did a v-if="reply.parent_id == comment.id"

and it works as expected!

9th July, 2018

Sidirgot started a new conversation Display Comment Replies For The Specific Comment • 2 months ago

Hello, so i created a commenting system with laravel and vue.

I can add comments, replies and everything, my only problem is that i cant for some reason figure out a way to get the replies for the specific comment.

This is the blade html :

<transition-group name="comment">
       <div class="user-comment border-bottom pt-5 pb-5 mb-3 " v-for="comment in comments" :key="comment.id">
        <div class="media">
         <img class="mr-3" src="" alt="" style="width:60px;">
         <div class="media-body">
           <h5 class="mt-0 mb-0">@{{ comment.name }} </h5>
           <p><em><small>@{{ comment.created_at | moment("from")}}</small></em></p>
         </div>
        </div>
        <article>
         @{{ comment.body }}
        </article>
        <div class="float-right">
         <a class="btn btn-outline-primary btn-sm" @click.prevent="reply(comment.id)">Reply</a>
        </div>
        <div class="ml-5 mt-2 border-top p-2" v-for="reply in replies" >
         <div class="media">
          <img class="mr-3" src="" alt="" style="width:60px;">
          <div class="media-body">
            <h5 class="mt-0 mb-0">@{{ reply.name }} </h5>
            <p><em><small>@{{ reply.created_at | moment("from")}}</small></em></p>
          </div>
         </div>
         <article>
           @{{ reply.body }}
         </article>
         <div class="mt-4 comment-action">
          <a href="#" class="btn btn-outline-primary btn-sm "><i class="fa fa-reply mr-1" aria-hidden="true"></i>Reply</a>
         </div>
        </div> <!--Reply Media Object div -->
         <transition-group name="fade" >
          <form class="mt-4 ml-5 mr-5" @submit.prevent="addCommentReply(comment.id)" v-if="repling == comment.id" :key="comment.id">
            <div class="form-row">
              <div class="col-sm-6">
                <div class="input-group mb-2">
                  <div class="input-group-prepend">
                    <div class="input-group-text"><i class="fa fa-at" aria-hidden="true"></i></div>
                  </div>
                  <input type="text" class="form-control" name="name" value="" placeholder="Name" v-model="name" required>
                  <span class="text-danger" :purifier.sync="purifier" >@{{ purifier }}</span>
                </div>
              </div>
            </div>
            <textarea name="body" rows="8" class="form-control" v-model="body" placeholder="Leave your comment" required></textarea>
            <button class="btn btn-primary float-right mt-3" type="submit">Post Comment</button>
          </form>
         </transition-group>

This is the axios get request to get the replies:

fetchReplies: function() {
  axios.get('/comment/replies/',{params:{id:this.id}})
       .then((response) => {            
        this.replies = response.data;
       })
 }

In my database every comment has a parent_id column witch indicates what comment it belongs to.

now if i do it this way all the replies appear on all the comments witch is correct since i need an index to bind the replies to but i cant seem to figure out the correct way to do this!

Any guidance is appreciated, thank you!

27th June, 2018

Sidirgot left a reply on Pagination Result Change When User Changes Pagination Page • 2 months ago

I found the solution searching in the docs.

This should be the way to display the pagination:

    {{ $artwork->appends(['search' => request()->query('search')])->links() }}

it passes the searched term on the other pages and its not loading all the db records

Sidirgot started a new conversation Pagination Result Change When User Changes Pagination Page • 2 months ago

Hello,

I created this function witch is searching on a category based on a value a user have provided.

public function specific(Request $request, $catname)
   {
   // Get the category name
    $category = Category::where('name',$catname)->first();
  //  Get all parent categories
        $categories = Category::where('p_id',0)->with('childs')->get();
 //  User search query
        $search = $request->specific;
 // get the records that much the query provided and  the category
        $artwork = Artwork::where('title','like','%'.$search.'%')
                     ->where('description','like','%'.$search.'%')
                     ->whereHas('category',function($q) use ($catname) {
                          $q->where('name',$catname);
        })->paginate(1);
   
        return view('pages.search.category')->withCategory($category)
                                       ->withArtwork($artwork)
                                       ->withCategories($categories);
     }

I am displaying the paginator like this:

{!! $artwork->links() !!}

The issue is that if i do a first search the result are correct and for my specific test it cames back with 2 total pages and 2 records but when i click on the second page for some reason it adds one more page and all the records from the database

I think the issue is somewhere in my $arwork query but i cant figure out what i am doing wrong!

Thank you in advance!

23rd March, 2018

Sidirgot left a reply on Get Specific Value From Many To Many Relationship • 5 months ago

@rin4ik it's frontend show for a single product!

Sidirgot started a new conversation Get Specific Value From Many To Many Relationship • 5 months ago

Hello everyone,

So i have a many to many relationship for product_options and options like this :

class ProductOption extends Model
{
    public function product()
        {
         return $this->belongsTo('App\Product');
         }

       public function option()
       {
        return $this->belongsToMany('App\Option','option_product');
       }
}



class Option extends Model
    {
         public function productoption()
    {   
         return $this->belongsToMany('App\ProductOption','option_product');
         }
}

Now i have product option details like option name, price etc in product options table and in options table i just store the option type like color and size.

This is what i tried:

   $product = Product::with(['productdescription','productimage'])->where('slug',$slug)->first();
       $options = ProductOption::where('product_id',$product->id)->with('option')->get();
           foreach ($options as $option) {
              foreach ($option->option as $key => $type) {
                  dd($type);
               }
          }

It works but i only get the type from the 1st product option and i cant seem to figure out how to get the option types from all of the product options i has.

17th March, 2018

Sidirgot started a new conversation Create A Single Record From Multidimensional Input Array's • 6 months ago

Hello, so i have 3 input array's all with different names like this:

<td><input class="input" type="text" name="p_color_name[]" placeholder="Red,  Blue etc.."></td>  

 <td><input class="input" type="text" name="p_color_price[]" placeholder="Price"></td>  

 <td><input class="input" type="text" name="p_color_stock[]" placeholder="Stock"></td>  

The user has the ability to add more rows like the above and add data so the end result could be:

P_color_name = { red,blue,green} p_color_price = {10,12,6} p_color_stock = {5,12,20}

So now i have 3 arrays and i want to create a single record for each row like:

red 10 5

blue 12 12

green 6 20

what i did is this:

foreach ($request->p_color_name as $color_name) {
         $color_option = new ProductOption();
           foreach ($request->p_color_price as $color_price) {
             foreach ($request->p_color_stock as $color_stock) {

                  $color_option->name = $color_name;

                  $color_option->p_option_price = $color_price;

                  $color_option->p_option_stock = $color_stock;
             }
          }  
           $product->productoption()->save($color_option);
           $option_type->productoption()->attach($color_option);    
     }

For 3 rows of data with the above code it gets the correct names and creates 3 different entries in the DB but for color_price and color_stock it only saves, in all 3 entries the same data witch is from the last row and complete skips the first 2 rows that it looped through.

How can i loop through and get the correct data for color_price and color_stock?

Sidirgot started a new conversation E-commerce Product Option Database Structure • 6 months ago

so i been developing an e-commerce website and i been thinking about how to handle product option like color and size, so my approach is this!

Table Structure

Products Option Table product_id / p_option_price / p_option_stock

Option Table id / type(color-size)

Option Value Table option_id / name(red,small,large) / image

Option Product Pivot table product_id / option_value_id

Relationships A product hasMany ProductOption

ProductOption hasMany OptionValues and OptionValues hasMany ProductOptions with Pivot table option products

Option hasMany OptionValues

My only issue is that the option value table will have a lot of duplicate value cause i will be adding each products values name and image into that table Any thoughts how to avoid that, by changing the structure a bit?

15th March, 2018

Sidirgot left a reply on Deleting An Image With Axios Request And Updating The Div • 6 months ago

@tykus i got stuck and couldn't get my mind around to figure out something that simple!!

Thank you tykus!!

Sidirgot started a new conversation Deleting An Image With Axios Request And Refreshing The Div • 6 months ago

Hello, this is my first try on using ajax and axios with laravel and i can't seem to figure out why it's behaving like this!

So i want to be able to delete a selected image with an axios request.

I build the process and the image gets deleted but the page wont refresh.

View

@if (App\ProductImage::where('product_id',$product->id)->exists())
                @foreach ($productimage as $image)
                <div class="column is-3">
                  <div class="image" style="width:200px;" >
                    <img src="{{ asset('images/productImages/'.$image->image)}}" alt="">
                  </div>

                  {{--  <form action="{{ route('DestroyProductImage',$image->id)}}" method="POST" enctype="multipart/form-data">
                    {{ csrf_field() }}
                   {{ method_field('DELETE')}}  --}}
                    <input type="text" value="" v-model="id">
                    <button  class="button is-danger" @click.prevent="DeleteImage({!! $image->id !!})"><i class="fa fa-minus"></i></button>
                  {{--  </form>  --}}
                </div>
                @endforeach
              @endif
            </div>

Axios Request

DeleteImage: function($id) {
        axios.delete('/manage/DestroyProductImage/'+$id)
            .then((response) => {               
              console.log(response)
            },(error) => {
              console.log(error)
            });
       }
     }

Controller

public function DestroyProductImage(Request $request, $id)
  {
        $productimage = ProductImage::where('id',$id)->first();

       $image = $productimage->image;
   
       $productImage = public_path('images/productImages/'.$image); // get previous image from folder
      File::delete($productImage);
         
      $productimage->delete();
       return response()->json('Image deleted');
     }

As I said the image gets deleted succefully but the page will not update and i don't know how to update the view! with the new data.

14th March, 2018

Sidirgot left a reply on Searching For Records Based On Values From A Form Not Working Properly • 6 months ago

@Cronix yes mate if i comment out the if statement for the title, the sku works but if both if statements are there i get nothing for sku only title.

It's really strange, been driving me crazy all day!

Sidirgot started a new conversation Searching For Records Based On Values From A Form Not Working Properly • 6 months ago

Hello , well i have a form in my index product page where i want to search based on the product title or the product sku.

Now the product title is stored in another table called ProductDescription with a hasOne relationship declared.

public function index(Request $request)
      {
        $products = Product::has('ProductDescription')->where('status', 1)->get();

        $this->validate($request,[
            'sku' =>  'max:255',
                'name' => 'max:255'
          ]);

          if ($request->has('sku')) {
            $sku  = $request->sku;
              $products = Product::with('ProductDescription')->where('sku',$sku)->get();
         }  

          if ($request->has('title')) {
             $title = $request->title;
             $products = Product::whereHas('productdescription', function($q) use ($title) {
                       $q->where('title', $title);
             })->get();
        }

        return view('backend.catalog.products.index')->withProducts($products);
  } 

This is my index function, now when i submit with a title value it works fine but when i type in a sku nothings comes back from the db!

Any ideas anyone?

13th March, 2018

Sidirgot left a reply on HasOne Relationship Not Saving • 6 months ago

@Bakanyaka well to tell you the trouth what i did was this

$manufacturer = Manufacturers::where('name',$request->manufacturer)->first();
    $product->manufacturer_id = $manufacturer->id;

But i thought it was wrong and maybe there was another way to go!

Thanks for the reply mate

Sidirgot started a new conversation HasOne Relationship Not Saving • 6 months ago

Hello, well i been trying to figure out this issue for the past hour without any luck!!

I have already done a lot of hasOne relationship in the past with other projects but at the moment i can't seem to figure out what is causing the issue.

I have a product table and a Manufacturers table in my db with a hasOne relationship declared like this:

Product Model

public function manufacturers()
 {
      return $this->hasOne('App\Manufacturers');
 }

Manufacturer Model

class Manufacturers extends Model
{
   public function product()
   {
         return $this->belongsTo('App\Product');
       }
}

Now i am getting the manufacturer option from a select field i have and the value comes as the manufacturer name and i am trying to save the relationship like this

$product->Manufacturers()->save($request->manufacturer);

And i been getting this error

"Type error: Argument 1 passed to Illuminate\Database\Eloquent\Relations\HasOneOrMany::save() must be an instance of Illuminate\Database\Eloquent\Model, string given, called in C:\xampp\htdocs\backend-ecom\app\Http\Controllers\Backend\ProductController.php on line 79

Anyone has any idea, it's been driving me crazy!

12th March, 2018

Sidirgot started a new conversation Random Staff When Running Route:list • 6 months ago

Hello everyone,

I am working on an eccommerce project with laravel and today i was checking my routes and for some reason after i run php artisan route:list i got all my routes but between some of the routes there was texts like

/ b( illuminate\foundation\auth\method_exists ╔ ═╗ z?* Illuminate\Foundation\Auth\property_exists ╔ ═╗ ╔* illuminate\foundation\auth\property_exists ╔ ═╗ >S, App\Http\Contr aU ╔ ╔ ═ +* App\Http\Controllers\LoggedinUserContoller [email protected] UserContoller [email protected] `0 1 ═ ۻ╔ ? Z╔ ═╗ ( App\Http\Controllers\Backend\public_path ZZ╔ ═╗ ( app\http\controlle aU ╔ ╝ ╔ ZZZ╔ ═ - /**ProductController ╔ ═╗ 4. app\http\controllers\backend\productco Z╔ ═╗ t/ Symfony\Component\Console\Helper\Table headers ╔ ═╗ - App\Http\Controllers\Backend\OrdersController ╔ ═╗ .- app\http\controllers\backend\orderscontroller ╗ ═ aU ╔ ╔ ═╗ #g, Symfony\Component\Console\Helper\Table rows ╔ ═╗ +* App\Http\Controllers\LoggedinUserContoller ╔ ═╗ w* app\http\controllers\loggedinusercontoller ╔ ═ aU ╔ ╔ ═╗ 2 ymfony\Component\Console\Helper\Table output ╔ ═╗ )- Symfony\Component\Console\Helper\Table style ╔ ═╗ |g2 ymfony\Component\Console\Helper\Table output ╔ ══ M ═ ╚aU ╔ ╔ ═ + Symfony\Component\Console\Helper\TableStyle mponent\Console\═ MP═ ╚aU ╔ ╔ ═╗ o* Symfony\Component\Console\Helper\is_scalar ymfony\Component\Console\Helper\array_values ╔ ═╗ ~ - symfony\component\console\helper\array_values ╔ ═╗ I ymfony\Component\Console\Helper\TableSeparator ╔ ═╗ / symfony\componen t\console\helper\tableseparator ╔ ═╗ •, Symfony\Component\Console\Helper\array_merge ╔ ═╗ ^, symfony\component\console\helper\array_merge ╔ ═╗ m* Symfony\Component\Console\Helper\Tabl eCell tor ╔ ═╗ x* symfony\component\console\helper\tablecell ╔ ═╗ } ( Symfony\Component\Console\Helper\str_pad at tor ╔ ═╗ ( symfony\component\console\helper\str_pad ╔ ═╗ < ll tor ╔ ═╗ x* symfony\component\console\helper\tablecell ╔ ═╗ } ( Symfony\Component\Console\Helper\str_pad at tor ╔ ═╗ ( symfony\component\console\helper\str_pad ╔ ═╗ < `( Symfony\Component\Console\Helper\explode arator ╔ ═╗ ╔l( symfony\component\console\helper\explode ╔ ═╗ )+ Symfony\Component\Console\Helper\TableStyle ╔ ═╗ ╔0* symfony\component \console\helper\is_scalar e ╔ ═╗ b* Symfony\Component\Console\Helper\is_object ╔ ═╗ F:* symfony\component\console\helper\is_object ╔ ═╗ pkY. Symfony\Component\Console\Helper\me thod_exists ╔ ═╗ k|. symfony\component\console\helper\method_exists ╔ ═╗ 2O( Symfony\Component\Console\Helper\gettype ╔ ═╗ C\( symfony\component\console\helper\gettype ╔ [7- Symfony\Component\Console\Helper\substr_count ╔ ═╗ '- symfony\component\console\helper\substr_count ╔ ═╗ 7+ Symfony\Component\Console\Helper\array_fill ╔ ═╗ uń+ symfony\comp onent\console\helper\array_fill ╔ ═╗ g5+ Symfony\Component\Console\Helper\array_diff e ╔ ═╗ N- Symfony\Component\Console\Helper\array_splice ╔ ═╗ Ε- symfony\component\console\helpe r\array_sp ! @ ! ╝P p ! ╗t @@ ! ╔╝[email protected] P╔ ! ╝sp ! p # ╝p # $ v╔ 0 PA═ @ ╝[email protected] ╔ B 0 ╔ p @ ` @╔ p╝! 0 p! " ! @ ! ╝P p ! ╗t @@ ! ╔╝[email protected] P╔ ! ╝sp ! p # ╝p # $ v╔ 0 PA═ @ X ╝╔╗B0 k X p X ╝Ѝp X ╗╝╗" X 0k Y x H @ ╝p ╔ v╔ 0 V {.H(S =ҀDS p#D v╔ 0 , " @ ╔ . 0 ╔ 0 . @ 0 X G . 0 p . ╗ГH . " p . @ . ╝P p . @ . ╔╝[email protected] 0╔ . ╝sp . p 0 ╝p 0 1 X═ ╝ X═ (8══ (8══ 0֚╗ ═ 0֚╗ ═ ═ Ȇ ═

Anyone Has any idea?

8th February, 2018

Sidirgot left a reply on OrderBy Created At On A Relationship Table • 7 months ago

@st8113 Very clean an nice solution but the problem is that now i do get jobs by created at but it gives me first all the jobs from one company, then the next company etc, so it kinda sorts the results by company and then by job and created at!

Any ideas?

7th February, 2018

Sidirgot started a new conversation OrderBy Created At On A Relationship Table • 7 months ago

Hello, so i have 2 tables in one to many relationship.

I have a Company table and a Job table.

A Company can post many jobs.

Now i want to fetch all the jobs that all the companies have made with both the company data and job data and also order them by created_at.

I am using this in my controller:

    $company = Company::with('job')->get();
    return view('Jobs.jobs')->withCompany($company);

And this is how i show the results in the blade file:

   @foreach ($company as $comp)
            @foreach ($comp->job as $jobs)
            <div class="col-xs-12 col-sm-6 col-md-4">
              <a href="{{route('availiableJob',$jobs->id)}}">
                <div class="thumbnail">
                    <img  src="{{asset('images/companylogos/'.$comp->logo)}}" alt="...">
                    <div class="caption">
                      <h3 class="text-center" style="text-transform:uppercase;font-size:16px;font-weight:600;">{{$jobs->name}}</h3>
                      <p class="pull-right" style="text-transform:uppercase;font-size:13px;font-weight:600;">{{$jobs->city}}</p>
                      <p style="text-transform:uppercase;font-size:13px;font-weight:600;">{{$jobs-

type}}

@endforeach @endforeach

If i go ahead and orderBy with this query i am getting created_at value from the company table, which is obvious. Now is there a way to orderBy the job created_at field?

21st September, 2017

Sidirgot left a reply on Vuejs Example Not Working With Bulma.io • 11 months ago

@Lars-Janssen Thats the main issue there is no console error !! I'll make everyhing from scratch and see if i missed something !! Thanks for helping mate!!

20th September, 2017

Sidirgot left a reply on Vuejs Example Not Working With Bulma.io • 1 year ago

@Lars-Janssen package.json is already done after i installed bulma!!

Bulma scss is importorted and it's working just fine only looks to be an issue with vue.

I also tried what with webpack.mix.js but i am getting error with npm run dev after i do that !!

Just a note it's not the first time i am using Bulma with laravel, i have done projects before with this kind of setup but it's the first time using vue with bulma and laravel!!

Sidirgot started a new conversation Vuejs Example Not Working With Bulma.io • 1 year ago

Hello, i just did a fresh install of laravel and i deleted bootstrap from package.json file before running npm install.

Also deleted the bootstrap file that it's adding in boostrap.js folder line 13.

Now here is the issue,

My View:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>ChatRoom | Welcome</title>
    <link rel="stylesheet" href="{{ asset('css/app.css')}}">
</head>
<body>


    <div id="app">
       <div class="panel has-text-centered">
          <div class="panel-heading">
            <span class="title is-1">Chatroom</span>
          </div>
        <div class="columns">
            <div class="column is-6 is-offset-3">
                <div class="box is-half">
                    <span >This is a message</span>
                    <example></example>
                 </div>
             </div>
         </div>
      </div>
   </div>

   <script href="{{ asset('js/app.js') }}"></script>
   </body>
  </html>

And the app.js file,

require('./bootstrap');

window.Vue = require('vue');



Vue.component('example', require('./components/Example.vue'));

const app = new Vue({
        el: '#app'  
});

I am trying to render the example component that we get out of the box but it doesn't work, plus there is no message in the console with google chrome!!!

Anyone got an idea why its now working?

19th September, 2017

Sidirgot left a reply on Mail Facade Authentication Error • 1 year ago

Found the solution 'from' => [ 'address' => env('MAIL_FROM_ADDRESS', ''), 'name' => env('MAIL_FROM_NAME', ''), ],

The problem had something to do with the above values in the mail config/mail.php!! For some reason if u keep the main values it doesn't need to authenticate but u can also pass a secondary argument with your details

Sidirgot started a new conversation Mail Facade Authentication Error • 1 year ago

Hello everyone, i am building a contact form for like the 15th time and for some reason i am having issues with the mail facade.

    public function send(Request $request) {
        $validator = Validator::make($request->all(), [
            'name' => 'required|max: 255',
            'email' => 'required|email',
            'message' => 'required|min: 10'
     ]);

        if($validator->fails()) {
           return Redirect::to(URL::previous(). '#findMe')
                             ->withErrors($validator)
                            ->withInput();
      }

    $data = [
        'SenderName' => $request->name,
        'email' => $request->email,
        'bodyMessage' => $request->message
    ];

    Mail::send('emails.contact', $data, function($message) use ($data){
      $message->from($data['email']);
      $message->to('[email protected]'); 
      $message->subject('Sidirgot.com Contact');
     });

  Session::flash('message', "Thank you for Contacting Me! I Will be in touch Within 24hours!");

    return Redirect::to(URL::previous() . "#findMe");
}

Now the error appears to be with the $message->to.

I am trying with mailtrap.io to see if it is going to work but no matter what email address i put inside the brackets in the $message->to variable i get authentication required error

If i take out the $message->to variable the message passes through but it's not being send to the dummy mailbox.

Why am i getting this authentication error even with a dummy email?

.env configuration are correct

    MAIL_DRIVER=smtp
    MAIL_HOST=smtp.mailtrap.io
    MAIL_PORT=2525
    MAIL_USERNAME=myusername
    MAIL_PASSWORD=mypassword
    MAIL_ENCRYPTION=tls

7th May, 2017

Sidirgot started a new conversation FULLTEXT Search • 1 year ago

Hello everyone,

I would like to implement FULLTEXT search on a project i am working on, for some reason i wont work.

Controller

   public function scopeSearch(Request $request)
    {
          $query = $request->q;
          $posts = DB::table('posts')->whereRaw("match(title, body) against (?)",[$query])
                      ->where('published', true)
                      ->orderBy('created_at', 'desc')
                      ->paginate(10);
      return view('blog.search')->withPosts($posts)->withQuery($query);
    }

I keep on getting this error

          SQLSTATE[HY000]: General error: 1191 Can't find FULLTEXT index matching the column 
          list (SQL: select count(*) as aggregate from `posts` where match(title, body) against 
          (fa) and `published` = 1)

The issue is that with phpmyadmin i can clearly see that i have both title and body with full text.

Any suggestions?

1st May, 2017

Sidirgot left a reply on Fetch Posts Based On Tag Where A Boolean Value Is True • 1 year ago

@martinbean tried it mate.

it works but it wont let me call in the view the tag names.

30th April, 2017

Sidirgot started a new conversation Fetch Posts Based On Tag Where A Boolean Value Is True • 1 year ago

Hello guys,

I Have posts table, a tag table and a pivot post_tag table connecting them

Now i have the tags that belong to the posts with a link so when someone click on one , it gives them a collection of all the posts that belong to that tag.

Tag Model

  public function posts()
   {
      return $this->belongsToMany('App\Post');
    }

Post Model

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

Controller

  public function TagShow($id)
    {
      $tag = Tag::find($id);
      return view('pages.TagIndex')->withTag($tag);
     }

Route

   Route::get('Tag/{id}',['uses'=>'[email protected]','as' =>'pages.TagIndex']);

This way everything works great. Now my problem is that i want to be a able to fetch only the posts that have published set to true.

I tried

public function TagShow($id)
     {
        $tag = Tag::find($id)->where('published',true);
        return view('pages.TagIndex')->withTag($tag);
      }

But i get Undefined property: Illuminate\Database\Eloquent\Builder::$name because i want to fetch the name of the tag i am searching on the view.

Any suggestions?

Sidirgot left a reply on Check If A Query Has Results • 1 year ago

@edoc thanks a bunch for the help mate!!! it worked like a charm!!

Sidirgot left a reply on Check If A Query Has Results • 1 year ago

Sorry guys for not posting it!!

here you go!

public function scopeSearch(Request $request)
   {
       $query = $request->q;
       $posts = Post::where('title','like',"%$query%")->paginate(10);
       return view('blog.search')->withQuery($query)->withPosts($posts);
   }

Sidirgot left a reply on Check If A Query Has Results • 1 year ago

@edoc tried it before u suggested, it says

call to a member function isempty() on string

Sidirgot started a new conversation Check If A Query Has Results • 1 year ago

Hello, i have a search box on my website

now on the view i have this

    @if ($query === null)
    {
        <h4 style="text-transform: lowercase;">no results for: #{{ $query }}</h4>
        }
    @else 
    {
                <h4 style="text-transform: lowercase;">results for: #{{ $query }}</h4>
        }
        @endif 

Now only the else statement works no matter the the query is null or not.

How can i check if the query has results in it ?

Sidirgot left a reply on Search Box Wont Work. • 1 year ago

Found the solution:

      public function scopeSearch(Request                                               
        $request)
  {
       $query = $request->q;
        $posts = 
       Post::where('title','like',"%$query%")-
          >paginate(10);
           return view('blog.search')-
                >withPosts($posts);
}

Sidirgot started a new conversation Search Box Wont Work. • 1 year ago

hello guys,

well i am trying to make a search box that i have in my website to work.

this is the function i am using

public function scopeSearch($search)
    {       
        $search = Post::where('title','like',"&$search&")->paginate(1);
        return view('blog.search')->withSearch($search);
    }

and this is the form

<ul>
         {{ Form::open(['method'=> 'get','route'=>'blog.search'])}}
         <input type="search" name="q" id="q" class="form-control" placeholder="Search...">
         <i class="fa fa-search"></i>
         {{ Form::close() }}
     </ul>

route

Route::get('search/results',['uses'=> '[email protected]', 'as' => 'blog.search']);

what am i missing?

25th April, 2017

Sidirgot started a new conversation How To Add Read More Link After Posts Body. • 1 year ago

Hello everyone ,

Well i got a small blog app that i am working on, and i would like to make a Read More Link after the body is fetched from the database This is my foreach loop , works great .

@foreach($posts as $post)
<div class="head">
<a class="title"  href="{{ route('blog.single',[$post->category->name, $post->slug]) }}">
        {{ $post->title }}</a>
    <h6>{{ $post->category->name }}</h6>
    <label style="margin-left:3em; margin-bottom:1em;">
    {{ date('M j, Y', strtotime($post-  >created_at)) }}</label>
    <a href="{{ route('blog.single',[$post->category->name, $post->slug]) }}">
    <img class="img-responsive"  src="{{ asset('images/MainPosts/' . $post->image) }}" />
    </a>
     <p class="ArticleBody">{{ substr(strip_tags($post->body), 0, 500) }}
        {{ strlen(strip_tags($post->body)) > 50 ? "...ReadMore" : "" }} 
    </p>
</div>
    @endforeach

As you can see i am using this function to shorten the body from the DB:

    {{ substr(strip_tags($post->body), 0, 500) }}
    {{ strlen(strip_tags($post->body)) > 50 ? "...ReadMore" : "" }}

Now is there a way that i can style The Read more part i have and make it a link?

22nd April, 2017

Sidirgot left a reply on Passing Different Functions In The Same View • 1 year ago

@Snapey Its only used in the index page !!!

@DirkZz Cant really get behind the idea of how to use a view composer, been reading about them trying to understand them.

Sidirgot left a reply on Passing Different Functions In The Same View • 1 year ago

Thanks for the reply's guys , just to clerify !!

What i am looking to do is this,

I have a sidebar in my index page and there i want to get the most popular posts, and thats counted by the view_counter column that i have in my post db table!!

Sidirgot started a new conversation Passing Different Functions In The Same View • 1 year ago

Hello everyone ,

This might be a kinda stupid question, cause i a certain that i am confusing the whole situation myself.

In a small blog app that i made i have an index page, where i made this function to get the 4 latest posts:

      public function index()
    {
            $posts = Post::orderBy('created_at', 'desc')->limit(4)->get();
            return view('pages.index')->withPosts($posts);
    }

it works great.

Now i want for the same index page to make a function to get the posts via the view_count. With all the reading i've been doing i kinda feel lost at the momment. How can i make multiple functions for the same view?

19th April, 2017

Sidirgot started a new conversation Laravel Blog App!! Create A Post But Not To Publish It!! • 1 year ago

hey guys,

Well here is the deal , i made a small blog app with laravel 5.4!! I am creating post via the backend and as soon as i create it, users in the front-end can see it !!

Now i would like to create the posts like i already do in the backend but for the front-end part to have a publish button so when and only when i click publish the post can be shown to the front-end users!!

From what i can understand i think i would probably need another table in the Database to be able to handle the backend posts and when i click publish the post will go to the main table!!!

Is this the only way?

30th March, 2017

Sidirgot started a new conversation Session Flash Message Timeout!! • 1 year ago

Hello everyone ,

So i have a Controller in witch i pass a flash message after i successfully make an etry!!

Everythings works great , i just wanted to know is there a way to controll the time the Flash Message appears on the new view ?

The message only dissapears after i refresh the page !!

Can you controll the timeout of the message without making the whole process via ajax?

29th March, 2017

Sidirgot left a reply on Two Parameters Via A Link • 1 year ago

@abi @vipin93 Thanks both of you guys i found out the solution according to your inputs!!!

Controller

           public function getSingle($category,$slug)
     {
            $post = Post::where('slug', '=', $slug)->first();
            return view('blog.single')->withPost($post);
    }

Route

       href="{{ route('blog.single',[$post->category->name,$post->slug])                
                }}"

This worked like a charm.

Thanks again guys!!

Sidirgot left a reply on Two Parameters Via A Link • 1 year ago

@abi Tryied that before i posted , that way i get trying to ge property of non object cause i am passing the slug from the post.

@tykus You couldnt get more specicif, thank you for that!! Any suggestions of how to pass both category and slug from the controller ?

   public function getSingle(Category $category, $slug)
              {
                  $post = Post::where('slug', '=', $slug)->first();
                  return view('blog.single')->withPost($post);
               }

Thats how i am thinking of going but cant seem to figure out how to get both of them from the var $post?

28th March, 2017

Sidirgot started a new conversation Two Parameters Via A Link • 1 year ago

hello everyone,

Category Controller:

   public function show(Category $category)
   {
      $posts = Category::findOrFail($category)->posts()->get();
      return view('pages.computer',compact('category'))->with('posts',$posts);
   }

Route:

     Route::get('Categories/{category}',[
              'uses' => '[email protected]',
               'as' => 'pages.computer']);

Now if i make a link like this:

      <a href="{{ route('pages.computer', ['Computers']) }}">

I get all the posts that belong to the Computer category witch great.

Now i want to use this route:

               Route::get('Categories/{category}/{slug}', 
                                       ['uses' => '[email protected]' , 
                                       'as' => 'blog.single'])>where('slug', '[\w\d\-\_]+');

And like i did with the above link to be able to pass the slug from the post:

          <a href="{{ route('pages.computer', ['Computers'],$post->slug) }}">

this is not working.

Sidirgot left a reply on Passing Parameter To The URI From A Link • 1 year ago

rcadhikari thanks for you time!! I did not try your approach cause Abi's worked just fine!!!

Abi you are awesome !! It worked Thank you!!

Sidirgot started a new conversation Passing Parameter To The URI From A Link • 1 year ago

Hello everyone ,

So i have a index page and i want to have a link in there to be able to load a view that is specific to a category i have in the database.

Category Controller:

 public function show(Category $category)
  {
    $posts = Category::findOrFail($category)->posts()->get();
   return view('pages.computer',compact('category'))->with('posts',$posts);
  }

Route:

  Route::get('{category}',[
          'uses' => '[email protected]',
          'as' => 'pages.computer']);

This way if i MANUALLY type in the URL localhost:8000/Computers <--witch is a category i have in the database i can get only the posts that are specific to that category.

So the query is working.

What i want is to be able from my index page to do something like : href ="{{ route('pages.computer') }} " and via this link to be able to load only the Computers category.

12th March, 2017

Sidirgot left a reply on How To Display Posts Via The Category • 1 year ago

Property [posts] does not exist on this collection instance. (View: C:\xampp\htdocs\blog\resources\views\pages\computer-id.blade.php)

i found the solution

<?php

namespace App\Http\Controllers;

 use Illuminate\Http\Request;
 use App\Post;
 use App\Category;

 class CatController extends Controller
 {
      public function show(Category $category)
    { 
     $posts = Category::findOrFail($category)->posts()->get();                                                                                                                           return view('pages.computer-id',compact('category'))
         ->with('posts',$posts);
  }

}

Sidirgot left a reply on How To Display Posts Via The Category • 1 year ago

Post Model

Sidirgot left a reply on How To Display Posts Via The Category • 1 year ago

I changed that and yet i get the same error!! I will keep on trying to see whats going on since i cant post here all the code for you to see!

Sidirgot left a reply on How To Display Posts Via The Category • 1 year ago

Property [posts] does not exist on this collection instance. (View: C:\xampp\htdocs\blog\resources\views\pages\computer-id.blade.php)

This is what i am getting now.

I will and watch what u said. Been struggling to get this to work for the past day!!

Sidirgot left a reply on How To Display Posts Via The Category • 1 year ago

After trying out what you said i am getting Undefined variable: category

Sidirgot started a new conversation How To Display Posts Via The Category • 1 year ago

This is my first laravel Application, and my first database based application so please be patient with me !! I will try to be specific!!

Categories Table: Id Name Timestamps

Posts table: Id title body slug Category_id timestamps

Lets say i have 4 catergories. Laptops, computers,phones,tablets

I want when i go to /computers to be able to get all the posts that are specific to that category.

Category Model: <?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Category extends Model
{
        protected $table ='categories';

        public function posts()
    {   
         return $this->hasMany('App\Post','Category_id');
        }
}

Post Model:

Edit Your Profile
Update

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