北漂张小白

1949 经验值

嗯,这样可以,但是不明白为什么!!谢谢jelly!!

<body>
    <div id="app">
        
        @yield('content')
        
    </div>

    <script src="{ mix('js/app.js') }"></script>
    @yield('bottom-js')
    <script>
        $('#flash-overlay-modal').modal();
    </script>
</body>

上面是app.blade.php文件,这样看来@section('bottom-js')并不在#app里面。
我看视频中的文件@section('js')应该也是这样的,不在#app里面。
我在show.blade.php文件里面去掉@include('vendor.ueditor.assets')就不会报这个错误。

页面中并没有写内联样式呀!

@extends('layouts.app')

@section('content')
    @include('vendor.ueditor.assets')

    <div class="container">
        <div class="row">
            <div class="col-md-8 col-md-offset-1">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        { $question->title }
                        @foreach($question->topics as $topic)
                            <a class="topic pull-right" href="/topic/{ $topic->id }">{ $topic->name }</a>
                        @endforeach
                    </div>

                    <div class="panel-body content">
                        {!! $question->body !!}
                    </div>

                    <div class="actions">
                        @if(Auth::check() && Auth::user()->owns($question))
                            <span class="edit">
                                <a href="/questions/{ $question->id }/edit">编辑</a>
                            </span>
                            <form action="/questions/{$question->id}" method="POST" class="delete-form">
                                { method_field('DELETE') }
                                { csrf_field() }
                                <button class="button is-naked delete-button">删除</button>
                            </form>
                        @endif
                    </div>

                </div>
            </div>
            <div class="col-md-3">
                <div class="panel panel-default">
                    <div class="panel-heading question-follow">
                        <h2>{ $question->followers_count }</h2>
                        <span>关注者</span>
                    </div>
                    <div class="panel-body">

                        <question-follow-button></question-follow-button>
                        <a href ="#editor" class="btn btn-primary pull-right">撰写答案</a>
                    </div>
                </div>
            </div>

            <div class="col-md-8 col-md-offset-1">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        { $question->answers_count } 个答案
                    </div>

                    <div class="panel-body">
                        @foreach($question->answers as $answer)
                            <div class="media">
                                <div class="media-left">
                                    <a href="">
                                        <img width="36px" src="{ $answer->user->avatar }" alt="{ $question->user->name }">
                                    </a>
                                </div>
                                <div class="media-body">
                                    <h4 class="media-heading">
                                        <a href="/questions/{ $answer->id }">
                                            { $answer->user->name }
                                        </a>
                                    </h4>

                                    {!! $answer->body !!}
                                </div>
                            </div>

                    @endforeach

                    @if(Auth::check())
                        <!-- 编辑器容器 -->
                        <form action="/question/{$question->id}/answer" method="post">
                            {!! csrf_field() !!}

                            <div class="form-group{ $errors->has('body') ? ' has-error' : '' }">

                                <script id="container"  name="body" type="text/plain">
                                    {!! old('body') !!}
                                </script>

                                @if ($errors->has('body'))
                                    <span class="help-block">
                                        <strong>{ $errors->first('body') }</strong>
                                    </span>
                                @endif
                            </div>


                            <button class="btn btn-success pull-right" type="submit">发布</button>
                        </form>

                    @else
                        <a href="{ url('login') }" class="btn btn-success btn-block">登录提交答案</a>
                    @endif

                    </div>

                </div>
            </div>
        </div>
    </div>

    @section('bottom-js')
        <!-- 实例化编辑器 -->
        <script type="text/javascript">

            var ue = UE.getEditor('container', {
                toolbars: [
                    ['bold', 'italic', 'underline', 'strikethrough', 'blockquote', 'insertunorderedlist', 'insertorderedlist', 'justifyleft','justifycenter', 'justifyright',  'link', 'insertimage', 'fullscreen']
                ],
                elementPathEnabled: false,
                enableContextMenu: false,
                autoClearEmptyNode:true,
                wordCount:false,
                imagePopup:false,
                autotypeset:{ indent: true,imageBlockLine: 'center' }
            });

            $(function(){

                function formatTopic (topic) {
                    return "<div class='select2-result-repository clearfix'>" +
                    "<div class='select2-result-repository__meta'>" +
                    "<div class='select2-result-repository__title'>" +
                    topic.name ? topic.name : "Laravel"   +
                        "</div></div></div>";
                }

                function formatTopicSelection (topic) {
                    return topic.name || topic.text;
                }

                $(".js-example-basic-multiple").select2({
                    tags: true,
                    placeholder: '选择相关话题',
                    minimumInputLength: 2,
                    ajax: {
                        url: '/api/topics',
                        dataType: 'json',
                        delay: 250,
                        data: function (params) {
                            return {
                                q: params.term
                            };
                        },
                        processResults: function (data, params) {
                            return {
                                results: data
                            };
                        },
                        cache: true
                    },
                    templateResult: formatTopic,
                    templateSelection: formatTopicSelection,
                    escapeMarkup: function (markup) { return markup; }

                });
            });

        </script>
    @endsection

@endsection
public function normalizeTopic(array $topics)
{

    return collect($topics)->map(function ($topic) {
        if ( is_numeric($topic) ) {
            Topic::find($topic)->increment('questions_count');
            return (int) $topic;
        }
        $newTopic = Topic::create(['name' => $topic, 'questions_count' => 1]);
        return $newTopic->id;
    })->toArray();
}


这个是什么意思,不太明白,主要是collect($topics)->map...是什么作用不太理解,之前有在哪里讲到吗??
$email = new  \App\Mail\LessonPublished(\App\User::first());
这个返回的不应该是一个user对象么?
然后 Mail::to(\App\User::first())->send($email);
这句我就更不理解了!麻烦jelly 给解释一下;谢谢!

下面是我在控制器中写的添加方法

public function store(Request $request)
    {
        $data = $request->all();
        $result = VenueRepositories::addVenue($data);
        if($result['status'] == 0){
            return Response::Json(['status'=>0, 'message'=>'添加场馆失败']);
        }
        return Response::Json(['status'=>1, 'message'=>'添加场馆成功']);
    }

当返回Response 时 就会报错:

Argument 1 passed to Encore\Admin\Middleware\PjaxMiddleware::filterResponse() must be an instance of Illuminate\Http\Response, instance of Illuminate\Http\JsonResponse given, called in /Users/zhangchunbo/www/trpiao/vendor/encore/laravel-admin/src/Middleware/PjaxMiddleware.php on line 34 and defined

PjaxMiddleware.php 如下

<?php

namespace Encore\Admin\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\MessageBag;
use Symfony\Component\DomCrawler\Crawler;

class PjaxMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param Request $request
     * @param Closure $next
     *
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function handle($request, Closure $next)
    {
        $response = $next($request);

        if (!$request->pjax() || $response->isRedirection() || Auth::guard('admin')->guest()) {
            return $response;
        }

        if (!$response->isSuccessful()) {
            return $this->handleErrorResponse($response);
        }

        $this->filterResponse($response, $request->header('X-PJAX-CONTAINER'))
            ->setUriHeader($response, $request);

        return $response;
    }

    /**
     * Send a response through this middleware.
     *
     * @param \Symfony\Component\HttpFoundation\Response $response
     */
    public static function respond(\Symfony\Component\HttpFoundation\Response $response)
    {
        $next = function () use ($response) {
            return $response;
        };

        (new static())->handle(Request::capture(), $next)->send();

        exit;
    }

    /**
     * Handle Response with exceptions.
     *
     * @param Response $response
     *
     * @return \Illuminate\Http\RedirectResponse
     */
    protected function handleErrorResponse(Response $response)
    {
        $exception = $response->exception;

        $error = new MessageBag([
            'type'      => get_class($exception),
            'message'   => $exception->getMessage(),
            'file'      => $exception->getFile(),
            'line'      => $exception->getLine(),
        ]);

        return back()->withInput()->withErrors($error, 'exception');
    }

    /**
     * Prepare the PJAX-specific response content.
     *
     * @param Response $response
     * @param string   $container
     *
     * @return $this
     */
    protected function filterResponse(Response $response, $container)
    {
        $crawler = new Crawler($response->getContent());

        $response->setContent(
            $this->makeTitle($crawler).
            $this->fetchContents($crawler, $container)
        );

        return $this;
    }

    /**
     * Prepare an HTML title tag.
     *
     * @param Crawler $crawler
     *
     * @return string
     */
    protected function makeTitle($crawler)
    {
        $pageTitle = $crawler->filter('head > title')->html();

        return "<title>{$pageTitle}</title>";
    }

    /**
     * Fetch the PJAX-specific HTML from the response.
     *
     * @param Crawler $crawler
     * @param string  $container
     *
     * @return string
     */
    protected function fetchContents($crawler, $container)
    {
        $content = $crawler->filter($container);

        if (!$content->count()) {
            abort(422);
        }

        return $this->decodeUtf8HtmlEntities($content->html());
    }

    /**
     * Decode utf-8 characters to html entities.
     *
     * @param string $html
     *
     * @return string
     */
    protected function decodeUtf8HtmlEntities($html)
    {
        return preg_replace_callback('/(&#[0-9]+;)/', function ($html) {
            return mb_convert_encoding($html[1], 'UTF-8', 'HTML-ENTITIES');
        }, $html);
    }

    /**
     * Set the PJAX-URL header to the current uri.
     *
     * @param Response $response
     * @param Request  $request
     */
    protected function setUriHeader(Response $response, Request $request)
    {
        $response->header(
            'X-PJAX-URL',
            $request->getRequestUri()
        );
    }
}
class LessonsController extends BaseController
{
    public function index(){
        $lessons = Lesson::all();
        return $this->collection($lessons, new LessonTransformer());
    }
}

最后这个collection 是调用的那里的方法?
还有new LessonTransformer() 虽然实例化了但是 什么时候调用的transform()这个函数呢??