mercredi 12 juin 2019

How to display multiple post in single blade by using two row(example starting post, expired_date post)

I have a category page and in this I want to display two types of box in single page, one is starting_post and old_post or expired, how can divide a single page in two part?

class FrontendController extends Controller { public function welcome()

{

    // @TODO Refactor This Line
    return view('welcome')

        ->with('title', Setting::first()->site_name)
        ->with('levels', Category::take(7)->get())

        ->with('levels', Category::take(7)->get())
        ->with('first_post', Post::orderBy('created_at','asc')->first())
        ->with('second_post', Post::orderBy('created_at', 'asc')->skip(1)->take(1)->get()->first())
        ->with('third_post', Post::orderBy('created_at','asc')->skip(2)->take(2)->get()->first())
        ->with('forth_post', Post::orderBy('created_at','asc')->skip(3)->take(3)->get()->first())
        ->with('HOME', Category::find(1))
        ->with('ABOUT US', Category::find(2))
        ->with('RESEARCH', Category::find(3))
        ->with('NEWS AND PUBLICATION', Category::find(4))
        ->with('EVENTS', Category::find(5))
        ->with('PEOPLE', Category::find(6))
        ->with('CONTACT US',Category::find(7));

}



public function singlePost($slug)

{
    $post=Post::whereSlug($slug)->first();

    return view('single')->with('post', $post)

                                ->with('content', $post)

                               ->with('levels', Category::take(7)->get());

}

public function category($slug)

{ $category=Category::whereSlug($slug)->firstOrFail();

   return view($category->getTemplateFile())->with('category', $category)

                                 ->with('title',$category->name)

                                 ->with('levels', Category::take(7)->get());

}

public function events($slug) { $post = Post::where('slug', $slug)->first();

   $coming_events = Post::where('id', '>', $post->id)->desc('id');
   $past_events = Post::where('id', '<', $post->id)->asc('id');

   return view('events_blade')

       ->with('post', $post)
           ->with('categories', Category::take(7)->get())
           ->with('next', Post::find($coming_events))
           ->with('prev', Post::find($past_events));

}

}



via Chebli Mohamed

mardi 11 juin 2019

no error, but data not shown, stuck in processing

enter image description here These are my files which is not showing my data in html only data is processing and no error also. I want to look my database through laravel in a html file but it's only processing and also not showing any error. so please help me on this error.

  • no error, the ajax response is good, but data not shown and processing box keeps showing.

  • Yajra 9.0

  • Laravel 5.8

MemberController.php

<?php

namespace App\Http\Controllers;
use App\Models\Member;
use Illuminate\Http\Request;
use Datatables;
use Validator;

class MemberController extends Controller
{
public function addSocialMember(){
  return view("home.views.social-member");
}

public function listMember(){
  return view("home.views.memberlist");
}

public function listAllMember(){
  $memberlist = Member::query();
  return Datatables::of($memberlist)->make(true);
}

public function saveMember(Request $request){
    $validator = Validator::make(array(
      "name"=>$request->name,
      "email"=>$request->email,
      "phone"=>$request->phone,
      "state"=>$request->state,
      "city"=>$request->city,
      "issue"=>$request->issue,
      "message"=>$request->message,
    ),array(
      "name"=>"required",
      "email"=>"required|unique:member",
      "phone"=>"required",
      "state"=>"required",
      "city"=>"required",
      "issue"=>"required",
      "message"=>"required",
    ));

    if($validator->fails()){

      return redirect("social-member")->withErrors($validator)->withInput();
    }else{

      //successfully we have passed our form
      $member = new Member;
      $member->name = $request->name;
      $member->email = $request->email;
      $member->phone = $request->phone;
      $member->state = $request->state;
      $member->city = $request->city;
      $member->issue = $request->issue;
      $member->message = $request->message;

      $member->save();

      $request->session()->flash("message","Member has been submitted form successfully");

      return redirect("social-member");
    }
}

}

Memberlist.blade.php

@extends("home.layouts.layout")

@section("title","Social Member | Bheekho Foundation")

@section("content")
<div class="container padding-top-three">
<br/>
  <blockquote><h4>We need  Help</h4></blockquote>
<br/>
<div class="row">
    <div class="col-md-12">
        <table class="table table-striped table-bordered" id="memberlist">
          <thead>
            <th>Name</th>
            <th>Email</th>
            <th>Phone</th>
            <th>State</th>
            <th>City</th>
            <th>Issue</th>
            <th>Describe Your Issues</th>
                  <th>Status</th>
          </thead>
        </table>
    </div>
  </div>

@endsection


web.php

<?php

Route::get("/","HomeController@homepage");

 //Social Member Route
Route::get("/social-member","MemberController@addSocialMember")->name("addsocialmember");


Route::get("/memberlist","MemberController@listMember")->name("listmember");


Route::get("/memberlist-data","MemberController@listAllMember")->name("listallmember");


Route::post("/save-member","MemberController@saveMember")->name("savemember");



via Chebli Mohamed

lundi 10 juin 2019

I have uploaded a pdf file and it's not showing on website when click on pdf link

I have uploaded the pdf link on website and when clicked on link it's not showing pdf file.

view

<div class="entry-content">

   <a  target="_blank" href=""><p style="font- 
      size: 
      18px;color: #468b10;">   </p>
   </a>

</div>

controller

      public function show($id)

    {

        $file=Post::find($id);

        $content = base64_decode($file->content);

        return response($content)->header('Content-Type', $file->file);
}

public function store(Request $request) {

if (request('file'))

{

        $file = request('file');

        $file_name = time() . $file->getClientOriginalName();

        $file->move('uploads/posts', $file_name);

        $data['file'] = 'uploads/posts/'.$file_name;

    }

}



via Chebli Mohamed

how to redirect and show error validateion in laravel

good day, I new in laravel Framework and I face this two problems : -
first one
I want to redirect to my page after 2 seconds automatically.
the second one
I make custom function call (is exist ) if this function returns true data I want to print "name exist before " but the problem here is form was rested when this function returns true and print message. how to prevent form resetting from inputs value? here is my code

controller code

enter code here
public function add(Request $request)

{
        // start add
    if($request->isMethod('post'))
    {
        if(isset($_POST['add']))
        {
            // start validatio array
        $validationarray=$this->validate($request,[
            //'name'  =>'required|max:25|min:1|unique:mysql2.products,name|alpha',
            'name'  =>'required|alpha',
            'price' =>'required|numeric',

            ]);
                // check name is exist

            if(true !=dBHelper::isExist('mysql2','products','`status`=? AND `deleted` =? AND `name`=?',array(1,1,$validationarray['name'])))
            {

                $product=new productModel();
                // start add
                $product->name=$request->input('name');
                $product->save();
                $add=$product->id;
                $poducten=new productEnModel();
                $poducten->id_product=$add;
                $poducten->name=$request->input('name');
                $poducten->price=$request->input('price');
                $poducten->save();
                $dataview['message']='data addes';




            }else{
                $dataview['message']='name is exist before';
            }

        }
    }
    $dataview['pagetitle']="add product geka";
    return view('productss.add',$dataview);
}

this is my routes

Route::get('/products/add',"produtController@add");
    Route::post('/products/add',"produtController@add");

this is my view

@extends('layout.header')
@section('content')
    @if(isset($message))
        
    @endif

    @if(count($errors)>0)
        <div class="alert alert-danger">
            <ul>
              @foreach($errors->all() as $error)
                  <li></li>

                  @endforeach

            </ul>

        </div>
        @endif

    <form role="form"  action="add" method="post" enctype="multipart/form-data">
        
        <div class="box-body">
            <div class="form-group">
                <label for="exampleInputEmail1">Employee Name</label>
                <input type="text" name="name" value="" class="form-control" id="" placeholder="Enter Employee Name">
            </div>

            <div class="form-group">
                <label for="exampleInputEmail1">Email Address</label>
                <input type="text" name="price" value="" class="form-control" id="" placeholder="Enter Employee Email Address">
            </div>
        </div>
        <!-- /.box-body -->
        <div class="box-footer">
            <button type="submit" name="add" class="btn btn-primary">Add</button>
        </div>
    </form>

@endsection



via Chebli Mohamed

dimanche 9 juin 2019

Error in redirect to previous page after successful register in Laravel?

I get this error "Header may not contain more than a single header, new line detected" when trying to redirect the user to the same page after successful registered. I can't see what I'm doing wrong

Here is the code in register controller

 public function showRegistrationForm()
 {
    if (session('link')) {
        $myPath     = session('link');
        $registerPath  = url('/register');
        $previous   = url()->previous();
        if ($previous = $registerPath)
        {
            session(['link' => $myPath]);
        }
        else
        {
            session(['link' => $previous]);
        }
    }
     else
     {
        session(['link' => url()->previous()]);
    }
    return view('auth.register');
  }

  protected function redirectTo()
  {
    return redirect(session('link'));
  }



via Chebli Mohamed

mercredi 5 juin 2019

How to post data in sub-category in website

I have made category table and created subcategory with the help of parent_id, and now I want to post data in subcategory in website, as I am able to post the data for category but not idea how to to do that for subcategory.

Create.blade.php

            @extends ('layouts.app')

@section('content')

<!-- End Sidebar scroll-->
</aside>
<!-- ============================================================== -->
<!-- End Left Sidebar - style you can find in sidebar.scss  -->
<!-- ============================================================== -->
<!-- ============================================================== -->
<!-- Page wrapper  -->
<!-- ============================================================== -->
<div class="page-wrapper">
    <!-- ============================================================== -->
    <!-- Container fluid  -->
    <!-- ============================================================== -->
    <div class="container-fluid">
        <!-- ============================================================== -->
        <!-- Bread crumb and right sidebar toggle -->
        <!-- ============================================================== -->

        <!-- ============================================================== -->
        <!-- End Bread crumb and right sidebar toggle -->
        <!-- ============================================================== -->
        <!-- ============================================================== -->
        <!-- Start Page Content -->
        <!-- ============================================================== -->
        <!-- Row -->
        <div class="row">
            <div class="col-lg-12">
                <div class="card">
                    <div class="card-header bg-info">
                        <div class="text-center">

                        </div>

                        @if(count($errors)>0)
                            <ul class="list-group">
                                @foreach($errors->all() as $error)
                                    <li class="list-group-item text-danger">
                                        
                                    </li>
                                @endforeach
                            </ul>
                        @endif

                            <div class="panel-heading">

                                <div class="text-center text-white">
                                    <b> <h2>Create a new Blog</h2></b>
                                </div>
                            </div><BR>
                            <div class="panel-body">
                                <form action="" method="post" enctype="multipart/form-data">
                                    


                                    <div class="form-group table-dark text-white">
                                        <label for ="category"><h3>Select a Menu</h3></label>
                                        <select name="category_id" id="category" class="form-control" >
                                            @foreach($levels as $category)
                                                <option value=""></option>
                                            @endforeach
                                        </select>
                                    </div>





                                    <div class="form-group text-white">
                                        <label for ="title"><h3>Option1 date/Name Manually</h3></label>
                                        <input type="text" name="opt_1" class="form-control text-danger">
                                    </div>

                                    <div class="form-group text-white">
                                        <label for ="title"><h3>Option2 date/Name Manually</h3></label>
                                        <input type="text" name="opt_2" class="form-control text-danger">
                                    </div>

                                    <div class="form-group text-white">
                                        <label for ="title"><h3>Title</h3></label>
                                        <input type="text" name="title" class="form-control text-danger">
                                    </div>


                                    <div class="form-group text-white">
                                        <label for ="featured"><h3>Image/Featured</h3></label> <input type="file" name="featured" class="form-control">
                                    </div>

                                    <div class="form-group text_white">

                                        <label for ="file"><h3>PDF file</h3></label><input type="file" name="file" class="form-control">
                                    </div>




                                    <div class="form-group text-white" >
                                        <label for ="content"><h3>Content</h3></label>
                                        <textarea name="content" id="content" cols="5" rows="5" class="form-control"> </textarea>
                                    </div>

                                    <div class="form-group">
                                        <div class="text-center">
                                            <button class="btn btn-success" type="submit"> Submit Blog</button>
                                        </div>
                                   </div>
                                </form>
                            </div>
                    </div>


                        </div>
                        @stop

                        @section('styles')

                            <link href="http://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.11/summernote.css" rel="stylesheet">

                        @stop

                        @section('scripts')

                            <script src="http://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.11/summernote.js"></script>


                            <script>
                                $(document).ready(function() {
                                    $('#content').summernote();
                                });

                            </script>
                        <!-- Row -->

                    javascript:
                    -------------
                    <script type="text/javascript">
                        $.ajaxSetup({
                            headers: {
                                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                            }
                        });

                        $(document).ready(function(){
                            $('#name').on('change',function(e){
                                console.log(e);
                                var parent_id= e.target.value;
                                $.getJSON('/your url/sub?parentID=' + parent_id, function(data){

                                    console.log(data);
                                    $('#sub_cat_id').empty();
                                    $.each(data,function(index, sub_cat_id){
                                        $('#sub_cat_id').append('<option value="'+sub_cat_id.id+'">'+sub_cat_id.name+'</option>');
                                    });
                                });

                            });
                        });
                    </script>


                    </div>
                </div>
            </div>
        </div>
        <!-- Row -->

@stop

FrontendController

              public function welcome()

{

    // @TODO Refactor This Line
    return view('welcome')

        ->with('title', Setting::first()->site_name)
        ->with('levels', Category::take(7)->get())
        ->with('first_post', Post::orderBy('created_at','desc')->first())
        ->with('second_post', Post::orderBy('created_at', 'desc')->skip(1)->take(1)->get()->first())
        ->with('third_post', Post::orderBy('created_at','desc')->skip(2)->take(2)->get()->first())
        ->with('forth_post', Post::orderBy('created_at','desc')->skip(3)->take(3)->get()->first())
        ->with('HOME', Category::find(1))
        ->with('ABOUT US', Category::find(2))
        ->with('RESEARCH', Category::find(3))
        ->with('NEWS AND PUBLICATION', Category::find(4))
        ->with('EVENTS', Category::find(5))
        ->with('PEOPLE', Category::find(6))
        ->with('CONTACT US',Category::find(7));

}

PostController.

            public function store(Request $request)
{
    $this->validate($request, [


        'title' =>'required',
        'opt_1'=>'required',
        'opt_2'=>'required',
        'featured'=>'mimes:jpeg,pdf,docx,png:5000',
        'file'=>'mimes:jpeg,pdf,docx,png:5000',
        'content'=>'required',
        'category_id'=>'required',


    ]);

    // Create Initial Required Data ARray
    $data = [

        'opt_1'=>$request->opt_1,
        'opt_2'=>$request->opt_2,
        'title'=>$request->title,
        'content'=>$request->content,
        'category_id'=>$request->category_id,


        'slug'=>str_slug($request->title)
    ];

    if(request('opt_1'))
    {
        $opt_1=request('opt_1');

    }




    // Optionally add 'featured' if found to the Data array
    if (request('featured'))
    {
        $featured = request('featured');
        $file_name = time() . $featured->getClientOriginalName();
        $featured->move('uploads/posts', $file_name);
        $data['featured'] = 'uploads/posts/'.$file_name;
    }

    // Optionally add 'file' if found to the Data array
    if (request('file')) {
        $file = request('file');
        $file_name = time() . $file->getClientOriginalName();
        $file->move('uploads/posts', $file_name);

// $content = base64_encode(file_get_contents($_FILES['pdf'['tmp_name']));

        $data['file'] = 'uploads/posts/'.$file_name;


        //$data->content=$content;
    }



    // Create the Post with the $data Array




    $post = Post::create($data);


    Session::flash('success', 'New Blog has been Published on Website for Particular Menu');

    return redirect()->back();

}



via Chebli Mohamed

lundi 3 juin 2019

Hod do i make discount percentage of products in Laravel

I want to show a discount percentage of my products.

I get this error:

Division by zero (0)

Can anyone suggest me that what's I'm doing wrong ?

@foreach ($Products as $product)
            <div>
                <span>% <br />OFF</span>
                <img src="" />
            </div>
            <div>
                <h2></h2>

                    <ins>  
<span>DHs</span>
Dhs   
</ins>
            </div>
@endforeach



via Chebli Mohamed