在我的函数中找出错误解析错误:语法错误,意外'}'

时间:2018-06-17 15:22:47

标签: php sql laravel laravel-5

大家好,我在函数库()中找不到错误:

这是以下代码:

public function store(Request $request)  {

   $post= new Post();
   $post->title = $request->input('title');

    if (Auth::check()) {

    $postPhoto = Auth::user()->photo;
    $emailpost = Auth::user()->email;

} else {

    $postPhoto = public_path('/images/def.jpg');
    $emailpost = $request->input('username');
}

     $post->photo = $postPhoto;
     $post->username = $emailpost;

      $post->body = $request->input('body');
   $post->save();

   return redirect ('/ed');
}

任何人都可以帮我找到它吗?

我的整个控制器PostsController.php:

<?php

namespace App\Http\Controllers;
use App\HomeModel;
use MaddHatter\LaravelFullcalendar\Event;

use DateTime;
use Illuminate\Http\Request;
//use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Auth;
//use Auth;
use App\Post;
use App\User;
use App\Role;
use App\Like;
use DB;
use JasonGrimes\Paginator;

class PostsController extends Controller
{
     protected $table = 'events'; // you may change this to your name table
  public $timestamps = true; // set true if you are using created_at and updated_at
  protected $primaryKey = 'id'; // the default is id
    protected $fillable = [
    'title', 'username', 'body', 
  ];  


  public function gerpub(){

$query = DB::table('posts')->where('posts.username','=',Auth::user()->email)
        ->select('posts.*');
 $query = $query->get();
        return view('gerpub',['posts'=> $query]);

  }

public function gerpubele(){

$query = DB::table('posts')->where('posts.username','=',Auth::user()->email)
        ->select('posts.*');
 $query = $query->get();
        return view('gerpubele',['posts'=> $query]);

  }


public function gerpubpar(){

$query = DB::table('posts')->where('posts.username','=',Auth::user()->email)
        ->select('posts.*');
 $query = $query->get();
        return view('gerpubpar',['posts'=> $query]);

  } 


  public function gerpubresp(){

$query = DB::table('posts')->where('posts.username','=',Auth::user()->email)
        ->select('posts.*');
 $query = $query->get();
        return view('gerpubresp',['posts'=> $query]);

  } 

    Public function posts() {

       $posts = Post::all();
       return view('ed', compact('posts'));

    }

Public function postsad() {

       $posts = Post::all();
       return view('pubad', compact('posts'));

    }

Public function postsens() {

       $posts = Post::all();
       return view('pubens', compact('posts'));

    }

Public function postsele() {

       $posts = Post::all();
       return view('pubele', compact('posts'));

    }

    Public function postspar() {

       $posts = Post::all();
       return view('pubpar', compact('posts'));

    }

      Public function postsresp() {

       $posts = Post::all();
       return view('pubresp', compact('posts'));

    }




     Public function postsel() {

       $posts = Post::all();
       return view('edad', compact('posts'));

    }

    Public function events() {

        $query = DB::table('events')->select('events.*');

          $itemsPerPage = 2 ;
    $currentPage  = isset( $_GET['page'] ) && is_numeric( $_GET['page'] ) ? $_GET['page'] : 1;
    $urlPattern   = '/evenement?page=(:num)';
    $totalItems   = $query->count();
    $donner   = $query->offset( ( $currentPage - 1 ) * $itemsPerPage )->limit( $itemsPerPage )->get();
    $paginator = new  Paginator( $totalItems, $itemsPerPage, $currentPage, $urlPattern );

               return view('evenement',['events'=> $donner,'paginator'=> $paginator]);


    }
    Public function posts1() {
       $posts = Post::all();
       return view('/home', compact('posts'));


    }

    Public function post(Post $post) {

     // $post = DB::table('posts')->find($id);
       return view('post', compact('post'));
        }

        Public function postad(Post $postad) {

     //$postad = DB::table('posts')->find($id);
       return view('postad', compact('postad'));
        }

          Public function postens(Post $postens) {

     //$postad = DB::table('posts')->find($id);
       return view('postens', compact('postens'));
        }



public function store(Request $request)  {

   $post= new Post();
   $post->title = $request->input('title');

    if (Auth::check()) {

    $postPhoto = Auth::user()->photo;
    $emailpost = Auth::user()->email;

} else {

    $postPhoto = public_path('/images/def.jpg');
    $emailpost = $request->input('username');
}

     $post->photo = $postPhoto;
     $post->username = $emailpost;

      $post->body = $request->input('body');
   $post->save();

   return redirect ('/ed');
}



public function storead(Request $request)
    {

   $post= new Post();
   $post->title=$request->input('title');

    if (Auth::check()) {

    $postPhoto = Auth::user()->photo;
    $emailpost = Auth::user()->email;
} else{

    $postPhoto = public_path('/images/def.jpg'); 
    $emailpost=$request->input('username')
}

     $post->photo=$postPhoto
   $post->username=$emailpost
      $post->body=$request->input('body');
   $post->save();
   return redirect ('/ed');
}


public function store1(Request $request1)
    {

   $post1= new Post();
   $post1->title=$request1->input('title');
   $post1->username=$request1->input('username');
     $post->photo=Auth::user()->photo;
      $post1->body=$request1->input('body');
   $post1->save();
   return redirect ('/home');
}

 Public function admin() {

$users= User::all();

       return view('addmin', compact('users'));
        }



        Public function admin1() {

             $users= User::all();

       return view('membre2', compact('users'));
        }





        public function addRole(Request $request) {

            $user = User::where('email', $request['email'])->first();
            $user->roles()->detach();

          if($request['role_elève'])
          {
             $user->roles()->attach(Role::where('name', 'Elève')->first());

          }

           if($request['role_ens'])
          {
             $user->roles()->attach(Role::where('name', 'Enseignant')->first());

          }

           if($request['role_parent'])
          {
             $user->roles()->attach(Role::where('name', 'Parent')->first());

          }

 if($request['role_admin'])
          {
             $user->roles()->attach(Role::where('name', 'Admin')->first());

          }

          return redirect()->back();
        }
public function like(Request $request)

{
        $like_s = $request->like_s;
        $post_id = $request->post_id;
       $change_like = 0;

       $like = DB::table('likes')
       ->where('post_id', $post_id)
       ->where('user_id', Auth::user()->id)
       ->first();

       if(!$like)
       {
          $new_like = new Like;
          $new_like->post_id = $post_id;
          $new_like->user_id = Auth::user()->id;
          $new_like->like = 1;
          $new_like->save();

          $is_like = 1;
        }

      elseif ($like->like == 1) 
      {
          DB::table('likes')
          ->where('post_id', $post_id)
          ->where('user_id', Auth::user()->id)
          ->delete();
          $is_like = 0;
        }  
         elseif ($like->like == 0) 
      {
          DB::table('likes')
          ->where('post_id', $post_id)
          ->where('user_id', Auth::user()->id)
          ->update(['like' => 1]);

           $is_like = 1;
          $change_like = 1;
        }  

        $response = array(  
             'is_like' => $is_like,
             'change_like' => $change_like
        );

        return response()->json($response, 200);

}

public function dislike(Request $request)

{
        $like_s = $request->like_s;
        $post_id = $request->post_id;
       $change_dislike = 0;

       $dislike = DB::table('likes')
       ->where('post_id', $post_id)
       ->where('user_id', Auth::user()->id)
       ->first();

       if(!$dislike)
       {
          $new_like = new Like;
          $new_like->post_id = $post_id;
          $new_like->user_id = Auth::user()->id;
          $new_like->like = 0;
          $new_like->save();

          $is_dislike = 1;
        }

      elseif ($dislike->like == 0) 
      {
          DB::table('likes')
          ->where('post_id', $post_id)
          ->where('user_id', Auth::user()->id)
          ->delete();
          $is_dislike = 0;
        }  
         elseif ($dislike->like == 1) 
      {
          DB::table('likes')
          ->where('post_id', $post_id)
          ->where('user_id', Auth::user()->id)
          ->update(['like' => 0]);
           $is_dislike = 1;
           $change_dislike = 1;
                   }  

        $response = array(  
             'is_dislike' => $is_dislike,
             'change_dislike' => 1,
        );

        return response()->json($response, 200);

}
public function statistics() {

$users = DB::table('users')->count();
$posts = DB::table('posts')->count();

$comments = DB::table('comments')->count();

$most_comments = User::withCount('comments')
               ->orderBy('comments_count', 'desc')
               ->first();
   // dd($most_comments->name);

   // $most_likes = User::withCount('likes')
     //          ->orderBy('likes_count', 'desc')
       //        ->first();
 //dd($most_likes->name);

//$active_user =               
   return view('/statistics', compact('users', 'posts', 'comments'));
}


            public function createresp()
        {

          return view('create1');
        }


         public function createeleve()
        { 
          return view('create2');
        }


         public function create3()
        {

          return view('create');
        }
        /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */

         public function isAllDay()
    {
        return (bool)$this->day;
    } 
    public function store4(Request $request)
    {   
        $time = explode(" - ", $request->input('daterange'));        
        $event                  = new HomeModel;
        $event->author            = Auth::user()->name;
        $event->name            = $request->input('name');
         $event->valid          = 1;  
        $event->title           = $request->input('title');
        $event->start      = $time[0];
        $event->end        = $time[1];
        $event->save();
        $request->session()->flash('success', 'The event was successfully saved!');
        return redirect('/list');
    }
public function storeresp(Request $request)
    {   
        $time = explode(" - ", $request->input('daterange'));        
        $event                  = new HomeModel;
        $event->author            = Auth::user()->name;
         $event->valid          = 1;   
        $event->name            = $request->input('name');
        $event->title           = $request->input('title');
        $event->start      = $time[0];
        $event->end        = $time[1];
        $event->save();
        $request->session()->flash('success', 'The event was successfully saved!');
        return redirect('/list1');
    }

    public function storeeleve(Request $request)
    {   
        $time = explode(" - ", $request->input('daterange'));        
        $event                  = new HomeModel;
        $event->author            = Auth::user()->name;
         $event->valid          = 0;  
        $event->name            = $request->input('name');
        $event->title           = $request->input('title');
        $event->start      = $time[0];
        $event->end        = $time[1];
        $event->save();
        $request->session()->flash('success', 'The event was successfully saved!');
        return redirect('/list2');
    }



     public function list()
    {
        $data = [
            'page_title' => 'Events',
            'event'     => HomeModel::orderBy('start')->get(),
        ];

        return view('list', $data);

    }
     public function listresp()
    {
        $data = [
            'page_title' => 'Events',
            'event'     => HomeModel::orderBy('start')->get(),
        ];

        return view('list1', $data);

    }
     public function listeleve()
    {
        $data = [
            'page_title' => 'Events',
            'event'     => HomeModel::orderBy('start')->get(),
        ];

        return view('list2', $data);

    }
     public function listele()
    {
        $data = [
            'page_title' => 'Events',
            'event'     => HomeModel::orderBy('start')->get(),
        ];

        return view('eleveeve', $data);

    }



    public function edit($id)
    {
        $event = HomeModel::findOrFail($id);
        $event->start;
        $event->end;

        $data = [
            'page_title'    => 'Edit '.$event->title,
            'event'         => $event,
        ];
        return view('edit',$data);
    }
     public function editresp($id)
    {
        $event = HomeModel::findOrFail($id);
        $event->start;
        $event->end;

        $data = [
            'page_title'    => 'Edit '.$event->title,
            'event'         => $event,
        ];
        return view('edit1',$data);
    }
     public function editeleve($id)
    {
        $event = HomeModel::findOrFail($id);
        $event->start;
        $event->end;

        $data = [
            'page_title'    => 'Edit '.$event->title,
            'event'         => $event,
        ];
        return view('edit2',$data);
    }
    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {

        $time = explode(" - ", $request->input('daterange'));        
        $event                  = HomeModel::where('id', $id)->first();
        $event->name            = $request->input('name');
        $event->title           = $request->input('title');
        $event->start      = $time[0];
        $event->end        = $time[1];
        $event->save();

       return redirect()->back();
    }

    public function updateresp(Request $request, $id)
    {

        $time = explode(" - ", $request->input('daterange'));        
        $event                  = HomeModel::where('id', $id)->first();
        $event->name            = $request->input('name');
        $event->title           = $request->input('title');
        $event->start      = $time[0];
        $event->end        = $time[1];
        $event->save();

       return redirect()->back();
    }
    public function updateeleve(Request $request, $id)
    {

        $time = explode(" - ", $request->input('daterange'));        
        $event                  = HomeModel::where('id', $id)->first();
        $event->name            = $request->input('name');
        $event->title           = $request->input('title');
        $event->start      = $time[0];
        $event->end        = $time[1];
        $event->save();

       return redirect()->back();
    }
    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $event = HomeModel::find($id);
        $event->delete();

        return redirect('/list');
    }

    public function destroyresp($id)
    {
        $event = HomeModel::find($id);
        $event->delete();

        return redirect('/list1');
    }

    public function destroyeleve($id)
    {
        $event = HomeModel::find($id);
        $event->delete();

        return redirect('/list2');
    }

}

1 个答案:

答案 0 :(得分:1)

您忘记在商店广告功能中$emailpost = $request->input('username')放置代码中的分号。分号似乎缺少许多行,例如下面的代码:

$post->photo=$postPhoto $post->username=$emailpost

此外,尝试统一练习缩进代码,以便其他看到代码的人不会很难阅读它。 下次尝试对这样的简单事情有敏锐的洞察力,因为有时小事情是最重要的。尝试查看@PaperT的链接:)